This Python program will convert kilometers to miles. It will take a distance in kilometers as input from the user and then convert it to miles using the conversion formula. The program will display the converted distance in miles as output.
- Read the distance in kilometers from the user.
- Perform the conversion using the formula: miles = kilometers * 0.621371.
- Display the converted distance in miles.
# Introduction print("Kilometers to Miles Converter") print("-----------------------------") # Read the distance in kilometers from the user kilometers = float(input("Enter distance in kilometers: ")) # Perform the conversion miles = kilometers * 0.621371 # Display the converted distance in miles print("Distance in miles:", miles)
Enter distance in Kilometres : 10
Distance in miles : 6.21371
In the above program, we prompt the user to enter the distance in kilometers. The input function is used to read the user’s input, which is then converted to a floating-point number using the float function.
Next, we perform the conversion by multiplying the distance in kilometers by the conversion factor of 0.621371, which represents the number of miles in one kilometer.
Finally, we display the converted distance in miles using the print function. The output is formatted to two decimal places for better readability.
For example, if the user enters a distance of 10 kilometers, the program will output the converted distance as 6.21371 miles.