Learn about Python Program to Convert Kilometers to Miles in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Python Program to Convert Kilometers to Miles
# Program to convert kilometers to miles # input from user km = float(input('Enter distance in kilometers: ')) # conversion factor basing on formula fac = 0.621371 # calculating the Miles mile = km * fac # print result print('%0.2f kilometers is equal to %0.2f miles' %(km, mile))
Enter distance in kilometers: 4 4.00 kilometers is equal to 2.49 miles
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : Python Program to Find Area of a Rectangle using Function