Program to Convert kilometers into miles in Python

Program to Convert kilometers into miles in Python

In this section, you will learn the program that convert kilometers into miles and miles into kilometers. 

If you are new to Python programming first you have to learn the topics given below:


Here, we are going to look at the Python program to convert kilometers to miles and miles to kilometers. Let us first understand kilometers and miles.

Kilometer:


Kilometer is the unit of length in metric system. This equivalent to 1000 meters.

Miles:


Mile is also a unit of length. This equivalent to 1760 yards.

Conversion principle:

1 kilometer is equal to 0.62137 miles.


Miles = kilometers * 0.62137
Kilometer = Miles / 0.62137

Now let's take a look at the code how to convert kilometers into miles and miles into kilometers using Python Programming.


Python code:
k = float(input("enter in kilometers ="))
convfactor = 0.62137
miles = k * convfactor
print("kilometers in miles =", miles)
m = float(input("enter in miles"))
convfactor = m/0.62137
print("miles in kilometers =", convfactor)
Output:
enter in kilometers = 32
kilometers in miles = 19.88384
enter in miles 4
miles in kilometers = 6.437388351545778

Recommended Post:
Python Program to check vowel or Consonant
Program to check character is alphabet or not in Python
Python to check whether the year is leap or not
Python to check if number is Positive, Negative or 0
Python Program to solve Quadratic equation
Program to generate Random numbers in Python
Program to swap two numbers in Python
Program to Add two numbers in Python
Python to convert decimal to binary, octal and hexadecimal

Python Program to find large number among three numbers
How to find absolute value of a number in Python
Program to add two binary numbers using bin function