Python Program to Convert Kilometers to Miles

Posted in

Python Program to Convert Kilometers to Miles
vinaykhatri

Vinay Khatri
Last updated on April 19, 2024

    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:

    Leave a Comment on this Post

    0 Comments