Python By Example

Convert Kilometers to Miles

by Jiffin Joachim Gomez on 24th February 2017

This is a simple python script to convert Kilometers to miles. The program asks the user to enter the kilometre to be converted to miles. Then the program multiplies the entered kilometres with the conversion factor value 0.621371 and gets the corresponding miles.

The input() function takes an input from the user and the float() function converts the input to floating-point number.

Program Sources

# Program to convert kilometers into miles

# Getting the value from user
kilometers = float(input('Enter The Kilometer value To be Converted: '))

# conversion factor
conv_factor = 0.621371

# calculate miles
miles = kilometers * conv_factor
print('%0.3f kilometers = %0.3f miles' %(kilometers,miles))

Program Output

Enter The Kilometer value To be Converted: 25
25.000 kilometers = 15.534 miles

Enter The Kilometer value To be Converted: 124
124.000 kilometers = 77.050 miles

Post a comment

Comments

Nothing yet..be the first to share wisdom.