In: Computer Science
Need this program in python. The data must be taken from user as input.
Write a program that prompts the user to select either Miles-to-Kilometers or Kilometers-to-Miles, then asks the user to enter the distance they wish to convert. The conversion formula is:
Miles = Kilometers X 0.6214
Kilometers = Miles / 0.6214
Write two functions that each accept a distance as an argument, one that converts from Miles-to-Kilometers and another that converts from Kilometers-to-Miles
The conversion MUST be done as a separate function that is called by the main program.
There are 15 distances in the data (shown below).
Display the original value and its unit (miles/kilometers) and then the converted value and unit.
Data:
Miles 16
Miles 28
Kilometers 39
Kilometers 44
Miles 11
Kilometers 71
Miles 59
Kilometers 62
Kilometers 34
Miles 19
Miles 25
Kilometers 71
Kilometers 88
Kilometers 90
Miles 110
Turn in your program code and the screen shot of the display. Remember you MUST use functions here.
def milesToKms(distance):
return distance/0.6214
def kmsToMiles(distance):
return distance*0.6214
choice=int(input("Convert
from\n1.Miles-to-Kilometers\n2.Kilometers-to-Miles\n"))
distance=float(input("Enter the distance: "))
if(choice==1):
kms=milesToKms(distance)
print("Miles: ",distance," Kilometers: ",kms)
else:
miles=kmsToMiles(distance)
print("Kilometers: ",distance," Miles: ",miles)