codescracker


python

Python Program to Convert Kilometres to Miles



« Previous Program Next Program »


Convert Kilometres to Miles in Python

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.

Python Programming Code to Convert Kilometres to Miles

Following python program ask from user to enter distance in kilometre to find the equivalent distance in mile:

# Python Program - Convert Kilometres to Miles
		
while True:
	print("Enter 'x' for exit.")
	km = input("Enter total kilometres: ")
	if km == 'x':
		break
	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:

python convert kilometres to miles

« Previous Program Next Program »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test