In this article, we will understand how to convert kilometers(km) to miles in python. After reading this article, you will be able to convert n km to miles in python, such as 10 km to miles.

Before converting km to miles, you must know the relation between km and miles, that is, how many miles are there in a km, which is

1 km  = 0.621371 miles

Python program to convert km to miles is given below

# read value to be converted in km
km = float(input('Enter distance in km: '))
# convert to miles
miles = km * 0.621371
print('Distance in miles is %0.4f' %miles)

Explanation
The program reads the number of kilometers as user input. User input in python is read using input() function.
It reads the values as a string which should be converted using float() function.
Since 1 km  = 0.621371 miles, in order to convert to miles, we need to multiply the value in km by this value. Example output of this program is given below.

Enter distance in km: 3
Distance in miles is 1.8641

Note that the value in miles is displayed till 4 decimal places.

Hope the article was useful. Click the clap below.

1
Liked the article ? Spread the word...