Python Program to Convert Kilometers to Miles

Python

Nicesnippets

291

18-06-2021


Hi Guys,

In this blog, I would like to share with you how to convert kilometers to miles using python. We will show how to get kilometers to miles in python. I am share with you python program to convert km(kilometers) to miles.

Here i will give example of how to convert kilometers to miles using python program so let's see the below example:

Example:


mile.py

# get 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))

Output

Enter value in kilometers: 3.5

3.50 kilometers is equal to 2.17 miles

It will help you....


Recommended Posts