In this article, we have provided a python program that is capable of converting kilometers in miles.
Prerequisite topics to create this program.
- Python Input, Output
- Python Data types
- Python Operators
Steps
- First, we ask the user the value in Kilometres
- Then we convert that into miles by multiplying the entered number with 0.621371, because there are 0.621371 miles in 1 kilometer.
- At last, using the print function we will print the value of miles.
Code
kilometers = float(input("Enter value in kilometers: "))
miles = kilometers * 0.621371
print("There are {0:.2f} Miles in {1:.2f} Kms ".format(miles,kilometers))
Output
Enter value in kilometers: 250
There are 155.34 Miles in 250.00 Kms
Behind the Code
In this above example we ask the user to enter the value of Kilometers, and using the float() function we convert the user input from string to floating data type. Then we multiply the value entered by the user by 0.621371 and get the value of miles.
People are also reading:
- Python Program to Remove Punctuations From a String
- WAP to find the greatest number among the three numbers
- Python Program to Check if a Number is Odd or Even
- WAP to find the average of list of numbers entered by the user
- Python Program to Display Calendar
- WAP in C++ & Python to calculate the size of each data types
- Python Program to Sort Words in Alphabetic Order
- Write a C++ Calculator to perform Arithmetic Operations using Switch Case
- WAP in C++ and Python to calculate 3X3 Matrix multiplication
Leave a Comment on this Post