Write a Python Program to Convert Kilometers to Miles

Given the number of kilometers as an input to the Python program your task is to convert the kilometers into miles.

As we already know one kilometer equals 0.62137119 miles.

Using the above Conversions let's write a Python program to convert the km to miles.

 

 

Write a Python Program to Convert Kilometers to Miles




Write a Python Program to Convert Kilometers to Miles

Inside the main program take a new variable  kilometers as km  and as a user enter the number of kilometers using the input function call.   Once the user enters the kilometers, convert it into a floating point value,  using float type conversion.

km = float(input("Enter Number of Kilometers : "))



Now take another variable named as miles and multiply the number of given kilometers with the fractional value 0.62137119.

miles = km * 0.62137119




Using the  print function call print the kilometers and miles conversion as shown below

print(f"{km} Kilometers is : %.2f Miles" %miles)




Python complete working code
==============================

km = float(input("Enter Number of Kilometers : "))
miles = km * 0.62137119
print(f"{km} Kilometers is : %.2f Miles" %miles)





Output
=============

Enter Number of Kilometers : 21
21.0 Kilometers is : 13.05 Miles



Output
==================

Enter Number of Kilometers : 45
45.0 Kilometers is : 27.96 Miles


OUTPUT
=============

Enter Number of Kilometers : 12.96
12.96 Kilometers is : 8.05 Miles



Conclusion
=================

Execute the above program by providing the random floating point value as an input to the Python program not down the result.

Comment down below if you have any suggestions are queries regarding the above program



Post a Comment

0 Comments