Articles

Python program to convert kilometers to miles

Python program to convert kilometers to miles


In this python programming guide, we are going to learn-

  • program to convert kilometers to miles in python

Program to convert Kilometers to Miles in Python

Program to convert kilometers to miles in python is a simple formula based code. Here we will accept input as kilometers from user and divide it by 1.609 to get the value in miles. Lets check how to do the same.

 

Please check our video tutorial on write a python program to convert kilometers to miles:

 

 

The program to convert kilometers to miles in python is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

kms = int(input("Enter length in KMs: "))
miles = kms/1.609

print("The length in miles is",round(miles,3))

The output of program to convert kilometers to miles in python is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter length in KMs: 23
The length in miles is 14.295

Few important tips about the program:

1. In the program, we take the user input in and convert it to integer data type.

2. Then we convert the KMs to Miles as 1 Miles = 1.609 KMs.

3. At the end, we round off the number to 3 decimal places using the round() function.

 

Write a python program to convert kilometers to miles snapshot:

python program to convert kilometers to miles

This wraps up our session on python program to convert kilometers to miles.


Basic Python Programs
Python Conversion Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :    Published Date : Nov 15,2022  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!