To convert kilometres to miles in python, you have to ask from user to enter the value of distance in kilometre to convert that distance into miles as shown here in the program given below.
To convert any number of kilometres into miles then just multiply that kilometre value into the value, that is, 0.621371. After multiplying the kilometre value into this number, then the answer you will get will be the same value but in mile.
Following python program ask from user to enter distance in kilometre to find the equivalent distance in mile:
# Python Program - Convert Kilometres to Miles print("Enter 'x' for exit.") km = input("Enter total kilometres: ") if km == 'x': exit(); else: kilometres = float(km) conversion_factor = 0.621371 miles = kilometres * conversion_factor print("%0.2f Kilometres = %0.2f Miles.\n" %(kilometres,miles))
Here is the sample run of the above Python program demonstrating how to convert distance from kilometre to miles:
Type value in kilometre say 10 and press enter to find the value in mile:
Following is same program on python shell: