fastread homefastrread library fastread menu

Python : Convert Kilometers to Miles

Tutorial by:Rizwan Abdullah      Date: 2016-06-16 00:49:13

❰ Previous Next ❱

Source Code

# Program to convert kilometers into miles 
# Input is provided by the user in kilometers

# take input from the user
kilometers = float(input('How many kilometers?: '))

# conversion factor
conv_fac = 0.621371

# calculate miles
miles = kilometers * conv_fac
print('%0.3f kilometers is equal to %0.3f miles' %(kilometers,miles))


How many kilometers?: 5.5
5.500 kilometers is equal to 3.418 miles




In this program, we use the ask the user for kilometers and convert it to miles by multiplying it with the conversion factor. With a slight modification, we can convert miles to kilometers. We ask for miles and use the following formula to convert it into kilometers.

kilometers = miles / conv_fac

❰ Previous Next ❱


Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website