Google News
logo
Python Program to Convert Kilometers to Miles
Here's a Python program that converts kilometers to miles :
Program :
kilometers = float(input("Enter the value in kilometers: "))
conv_fac = 0.621371  # Conversion factor

# Calculate miles
miles = kilometers * conv_fac

# Display the result
print(f"{kilometers} kilometers is equal to {miles:.2f} miles.")
Output :
Enter the value in kilometers: 9
9.0 kilometers is equal to 5.59 miles.
In this program, we first ask the user to input the distance in kilometers. We then define the conversion factor as 0.621371, which is the number of miles in one kilometer.

We then multiply the distance in kilometers by the conversion factor to get the equivalent distance in miles. Finally, we display the result using the `print()` function, formatting the output to two decimal places using the f-string notation.