Slider

Python Program to Convert Kilometers to Miles.

In this tutorial, will learn how to convert Kilometers to Miles using Python Programming. Algorithm to Convert Kilometers to Miles.
In this tutorial, will learn how to convert Kilometers to Miles using Python Programming. We'll cover the algorithm, provide a step-by-step guide, and offer Python code with explanations.

Understanding the Conversion.

The conversion from kilometers to miles involves a simple mathematical formula. The relationship between kilometers (K) and miles (M) is given by:

Formula: Miles = Kilometers × 0.621371

This formula states that one kilometer is approximately equal to 0.621371 miles.

Algorithm to Convert Kilometers to Miles.

Step 1: Take the value of kilometers as input from the user.
Step 2: Use the formula M = Km x 0.621371 to calculate Miles and store the result in a variable.
Step 3: Print the value stored in the variable as output. 

Python Code:
# Python program to convert kilometers to miles
distance_in_km = float(input("Enter distance in kilometers: "))

conversion_factor = 0.621371
# Calculating miles
distance_miles = distance_in_km * conversion_factor

# Displaying the result
print(f"{distance_in_km} kilometers is equal to {distance_miles:.2f} miles.")
Output:
Enter distance in kilometers: 12
12.0 kilometers is equal to 7.46 miles.

This Python program provides a straightforward way to convert distances from kilometers to miles. Understanding such conversions is crucial in various applications, including travel, fitness tracking, and geographic calculations.
0

No comments

Post a Comment

both, mystorymag

DON'T MISS

Tech News
© all rights reserved
made with by AlgoLesson
Table of Contents