Algorithm


Input:
      Get the distance in kilometers as input from the user.
Conversion:
      Use the conversion factor: 1 kilometer = 0.621371 miles.
      Multiply the distance in kilometers by the conversion factor to get the equivalent distance in miles.

Output:
      Display the converted distance in miles.

Code Examples

#1 Example- Kilometers to Miles

Code - Python Programming

# Taking kilometers input from the user
kilometers = float(input("Enter value in kilometers: "))

# conversion factor
conv_fac = 0.621371

# calculate miles
miles = kilometers * conv_fac
print('%0.2f kilometers is equal to %0.2f miles' %(kilometers,miles))
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter value in kilometers: 3.5
3.50 kilometers is equal to 2.17 miles
Advertisements

Demonstration


Python Programing Example to Convert Kilometers to Miles-DevsEnv