USING PYTHON 2 The United States uses the English system of (length) measurement
ID: 3726484 • Letter: U
Question
USING PYTHON 2
The United States uses the English system of (length) measurements. The rest of the world uses the metric system. So, people who travel abroad and companies that trade with foreign partners often need to convert English measurements to metric ones and vice versa.
Here is a table that shows the six major units of length measurements of the English system:
English 1 inch = 2.54 cm 1 foot = 12 in. 1 yard = 3 ft. 1 rod = 5(1/2) yd. 1 furlong = 40 rd. 1 mile = 8 fl.
Develop the functions 'inches_to_cm', 'feet_to_inches', 'yards_to_feet', 'rods_to_yards', 'furlongs_to_rods', and 'miles_to_furlongs'.
Then develop the functions 'feet_to_cm', 'yards_to_cm', 'rods_to_inches', and 'miles_to_feet'.
Your function should have the similar format like this:
def inches_to_cm(x)
return inches*2.54
Call your function to test your results.
Explanation / Answer
Python program to convert English measurements to metric ones and vice versa.
Code
# 'inches_to_cm', 'feet_to_inches', 'yards_to_feet', 'rods_to_yards', 'furlongs_to_rods', and 'miles_to_furlongs'.
Cm_Inch = 2.54
Feet_Inch = 12
Yard_Feet = 3
Rod_Yard = 5.5
Furlog_Rod = 40
Mile_Furlog = 8
#function to display the menu
def display_menu():
print('Menu')
print('1.Centimeter to Inches.')
print('2. Inches to Centimeter.')
print('3. Feet to Inches.')
print('4. Inches to Feet.')
print('5. Yards to Feet.')
print('6. Feet to Yards.')
print('7. Rods to Yards.')
print('8. Yards to Rods.')
print('9. Furlongs to Rods.')
print('10. Rods to Furlongs.')
print('11. Miles to Furlongs.')
print('12. Furlongs to Miles.')
print('13. Exit')
# function to convert cm to inches
def convert_cm_to_inch(val):
return val / Cm_Inch
#function to convert inches to centimeters
def convert_inch_to_cm(val):
return val * Cm_Inch
#function to convert from feet_to_inch
def convert_feet_to_inch(val):
return val * Feet_Inch
#function to convert from Inches to Feet
def convert_inch_to_feet(val):
return val / Feet_Inch
#function to convert from Yards to Feet.
def convert_yard_to_feet(val):
return val * Yard_Feet
#function to convert from feet to yard
def convert_feet_to_yard(val):
return val / Yard_Feet
#function to convert from rod to yard
def convert_rod_to_yard(val):
return val * Rod_Yard
#function to convert from yard to rod
def convert_yard_to_rod(val):
return val / Rod_Yard
#function to convert from Furlongs to Rods.
def convert_furlog_to_rod(val):
return val * Furlog_Rod
#function to convert from Rods to Furlogs.
def convert_rod_to_furlog(val):
return val / Furlog_Rod
#function to convert from Miles to Furlogs.
def convert_mile_to_furlog(val):
return val * Mile_Furlog
#function to convert from Furlongs to Miles.
def convert_furlog_to_mile(val):
return val / Mile_Furlog
if __name__ == "__main__":
choice =1 #for storing user choice for conversion
while(not(choice==13)):#performs the loop until exit 13
display_menu()# display the menu
#prompt the user for input
ch = input("Enter your choice of conversion :")
#if the choice is not number the accept number from the user
if not(ch.isnumeric()):
while(not(ch.isnumeric())):
print("please enter digits(1-13).")
ch = input("Enter the Answer :")
choice = int(ch)
if (choice == 1):#convert cm to inches
inputt = float(input("Enter the centimeters: "))
print("%s centimeters is %s inches" % (inputt, convert_cm_to_inch(inputt)))
elif(choice == 2):#to convert inches to centimeters
inputt = float(input("Enter the Inches: "))
print("%s Inches is %s centimeters" % (inputt, convert_inch_to_cm(inputt)))
elif(choice == 3): #conversion from Feet to Inches.
inputt = float(input("Enter the Feet: "))
print("%s Feet is %s Inches" % (inputt, convert_feet_to_inch(inputt)))
elif(choice == 4): # conversion from Inches to Feet
inputt = float(input("Enter the Inches: "))
print("%s Inches is %s Feet" % (inputt, convert_inch_to_feet(inputt)))
elif(choice == 5): # conversion from Yards to Feet.
inputt = float(input("Enter the Yard: "))
print("%s Yard is %s Feet" % (inputt, convert_yard_to_feet(inputt)))
elif(choice == 6): # conversion from Feet to Yards.
inputt = float(input("Enter the Feet: "))
print("%s Feet is %s Yard" % (inputt, convert_feet_to_yard(inputt)))
elif(choice == 7): #conversion from Rods to Yards.
inputt = float(input("Enter the Rods: "))
print("%s Rod is %s Yards" % (inputt, convert_rod_to_yard(inputt)))
elif(choice == 8): #conversion from Yards to Rods.
inputt = float(input("Enter the Yards: "))
print("%s Yards is %s Rods" % (inputt, convert_yard_to_rod(inputt)))
elif(choice == 9): #conversion from Furlongs to Rods.
inputt = float(input("Enter the Furlog: "))
print("%s Furlog is %s Rods" % (inputt, convert_furlog_to_rod(inputt)))
elif(choice == 10): #conversion from Rods to Furlogs.
inputt = float(input("Enter the Rods: "))
print("%s Rods is %s Furlog" % (inputt, convert_rod_to_furlog(inputt)))
elif(choice == 11): #conversion from Miles to Furlogs.
inputt = float(input("Enter the Miles: "))
print("%s Miles is %s Furlogs" % (inputt, convert_mile_to_furlog(inputt)))
elif(choice == 12): #conversion from Furlongs to Miles.
inputt = float(input("Enter the Furlog: "))
print("%s Furlog is %s Miles" % (inputt, convert_furlog_to_mile(inputt)))
elif(choice == 13):
print('Thank you')
else:
print('Sorry!!! Invalid user entry')
Sample run:
Menu
1.Centimeter to Inches.
2. Inches to Centimeter.
3. Feet to Inches.
4. Inches to Feet.
5. Yards to Feet.
6. Feet to Yards.
7. Rods to Yards.
8. Yards to Rods.
9. Furlongs to Rods.
10. Rods to Furlongs.
11. Miles to Furlongs.
12. Furlongs to Miles.
13. Exit
Enter your choice of conversion :a
please enter digits(1-13).
Enter the Answer :1
Enter the centimeters: 121
121.0 centimeters is 47.63779527559055 inches
Menu
1.Centimeter to Inches.
2. Inches to Centimeter.
3. Feet to Inches.
4. Inches to Feet.
5. Yards to Feet.
6. Feet to Yards.
7. Rods to Yards.
8. Yards to Rods.
9. Furlongs to Rods.
10. Rods to Furlongs.
11. Miles to Furlongs.
12. Furlongs to Miles.
13. Exit
Enter your choice of conversion :13
Thank you
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.