In this program, you will learn how to convert kilometers to miles.
# This program to convert kilometers to miles
#kilometers = 12.5
kilometers = float(input('Enter the value in kilometers: '))
#conversion factor
conversion_factor = 0.621371
#convert kilometers to miles
miles = kilometers * conversion_factor
print('%0.2f kilometers is equal to %0.2f miles' %(kilometers,miles))
Enter the value in kilometers: 20
20.00 kilometers is equal to 12.43 miles
In this program, we use the kilometers variable to hold the value of entered kilometers by you.
Note: 1 Kilometer is equal to 0.621371 miles.
miles = kilometers * conversion_factor
Use the following formual to convert Miles to Kilometers
kilometers = miles / conversion_factor
The following topics can be useful to understand this program.