- These two little python programs can convert
kilometers to miles
andmiles to kilometers
- Python3
- or a online python compiler with the output
- First download the
.py
files from releases and run them with python3 and enter the kilometers or miles. - Or copy the codes and paste on a online compiler and run it.
# Taking kilometers input from the user
kilometers = float(input("Enter value in miles: "))
# conversion factor
conv_fac = 0.621371
# calculate miles
miles = kilometers / conv_fac
print('%0.2f miles is equal to %0.2f kilometers' %(kilometers,miles))
# Taking kilometers input from the user
kilometers = float(input("Enter value in kilometers: "))
# conversion factor
conv_fac = 0.621371
# calculate miles
miles = kilometers * conv_fac
print('%0.2f kilometers is equal to %0.2f miles' %(kilometers,miles))