Python program to convert kilometers to miles

Created with Sketch.

Python program to convert kilometers to miles

Here, we are going to see the python program to convert kilometers to miles. Let’s understand kilometers and miles first.

Kilometer:

The kilometer is a unit of length in the metric system. It is equivalent to 1000 meters.

Miles:

Mile is also the unit of length. It is equal to 1760 yards.

Conversion formula:

1 kilometer is equal to 0.62137 miles.

  1. Miles = kilometer * 0.62137
  2. Kilometer = Miles / 0.62137

See this example:

  1. # Collect input from the user
  2. kilometers = float(input(‘How many kilometers?: ‘))
  3. # conversion factor
  4. conv_fac = 0.621371
  5. # calculate miles
  6. miles = kilometers * conv_fac
  7. print(‘%0.3f kilometers is equal to %0.3f miles’ %(kilometers,miles))

Output:

Python Basic Programs8

 

Leave a Reply

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