Python program to convert kilometers to miles
In this article, you will learn how to convert kilometers to miles using Python programming language. The Kilometer unit is used to measure length or distance. We can also measure the distance in miles. Sometime, we need to express the kilometers in term of miles.
In the given example, we have asked the user to enter the kilometers and stored in a variable km. Since 1 kilometer is equivalent to 0.621371 miles, we can get the same miles by multiplying the entered value with 0.621371.
# Getting kilometers input from the user
km = float(input("Enter value in kilometers: "))
# conversion factor
conv_fac = 0.621371
# calculating miles
miles = km * conv_fac
print('%0.2f kilometers is equal to %0.2f miles' %(km,miles))
Output1
Enter value in kilometers: 200
200.00 kilometers is equal to 124.27 miles
Output2
Enter value in kilometers: 320
320.00 kilometers is equal to 198.84 miles
Related Articles
Python program for insertion sort
Merge sort program in Python
Selection sort program in Python
Bubble sort program in Python
Power of a number using recursion in Python
Python dict inside list
Pandas string to datetime
Convert Excel to CSV Python Pandas
Python add list to list
Python Pandas Dataframe to CSV
Python compare two lists
Remove element from list Python
Python iterate list with index
Python program to sum all the numbers in a list
Python print without newline
Python iterate list with index
Python add list to list
Python convert xml to dict
Python dict inside list
Python convert dict to xml
Python weather api
Python raise keyword