This Python programming tutorial will teach you a simple Python 3 program to convert kilometers to miles. Before moving ahead, make sure you know about basic Python programming concepts such as variables, data types, and operators. If you love books, check out these best books to learn Python programming.
Python 3 Program To Convert Kilometers to Miles
As you know, 1 KM is equal to 0.621371 Miles. Therefore, to convert kilometers to miles, you have to divide the number entered by a user by 1.609.
Here is the Python source code you can refer to:
#Python program to convert Kilometers to Miles KM = float(input(print("Enter Kilometer = "))) M = KM/1.60934 print("Miles = ", M)
Python 3 Program to Convert Miles to Kilometers
1 mile is equal to 1.60934 KMs. Therefore, to convert miles to kilometers, you have to multiply the value by 1.60934.
def convertMilestoKm(value): value = value * 1.60934 return value MilesInput = float(input(print("Enter Miles: "))) KM = convertMilestoKm(MilesInput) print("Kilometers = ", KM)
Enter Miles: 2
Kilometers = 3.21868
Other Python programs for practice
- Python 3 Program To Add Two Matrices.
- Python 3 Program to Check Armstrong Number.
- Python 3 Program to Find the Sum of Natural Numbers.
- Python 3 Program To Find The Factorial Of A Number.
- Python 3 Program to Find Largest Among Three Numbers.
- Python 3 Program to Check Leap Year.
- Python 3 Program To Check If Number Is Positive Or Negative.
- Python 3 Program To Convert Celsius To Fahrenheit.
- Python 3 Program to Generate A Random Number.
- Python 3 Program To Swap Two Numbers.
- Python 3 Program To Solve A Quadratic Equation.
- Python 3 Program to Calculate The Area of a Triangle.
- Python 3 Program to Find the Square Root of A Number.
- Python 3 Program To Add Two Numbers.
- Python 3 Program to Print Hello World.
Hello Friends! I am Himanshu, a hobbyist programmer, tech enthusiast, and digital content creator.
With CodeItBro, my mission is to promote coding and help people from non-tech backgrounds to learn this modern-age skill!