0

Write a problem that asks the user to enter a whole number of inches and converts that length to feet and inches.

Can you please explain the code too. Thank you.

8th Sep 2016, 1:15 AM
Manahari Dahal
Manahari Dahal - avatar
2 Respostas
+ 5
total_inches = int(input("input length in inches: ")) feet = total_inches // 12 inches_remained = total_inches % 12 print("{0} inches equals {1} feet and {2} inches".format(total_inches, feet, inches_remained)) ----- As we know 1 feet equals 12 inches so any number of inches can be presented in feet and inches according to formula: total_inches = 12*feet + inches_remained, where inches_remained is integer from 0 to 11. 1st line: getting the 'total_inches' from user and converting it from string to integer 2nd line: calculating 'feet' using floor division 3rd line: performing modulo operation to get 'inches_remained' 4th line: printing the results using format method.
8th Sep 2016, 3:18 AM
Textobot
Textobot - avatar
0
thank you
8th Sep 2016, 3:31 AM
Manahari Dahal
Manahari Dahal - avatar