Python Program to Convert Kilometers to Miles – 2024

Hey guys, in this blog we will see a Python Program to Convert Kilometers to Miles.

Code

# Python Program to Convert Kilometers to Miles

# Taking kilometers input from the user
kilometers = float(input("Enter the distance in kilometers -> "))

# conversion factor
conversion_factor = 0.621371

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

Output

Enter the distance in kilometers -> 12
12.00 kilometers is equal to 7.46 miles
Enter the distance in kilometers -> 10
10.00 kilometers is equal to 6.21 miles
Enter the distance in kilometers -> 1
1.00 kilometers is equal to 0.62 miles

We are simply converting Kilometers to Miles using a conversion factor which is 0.621371.

I Kilometer = 0.621371 Miles

Check out our other python programming examples

Abhishek Sharma
Abhishek Sharma

Started my Data Science journey in my 2nd year of college and since then continuously into it because of the magical powers of ML and continuously doing projects in almost every domain of AI like ML, DL, CV, NLP.

Articles: 514

Leave a Reply

Your email address will not be published. Required fields are marked *