Write a program that reads a length in feet and inches (example: 3 ft and 2 in) and outputs the equivalent length in meters and centimeters example: 1.5 m and 22 mm). Use at least three functions: one for input, one or more for calculating, and one for output. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. There are 0.3048 meters in a foot, 100 centimeters in a meter, and 12 inches in a foot.

Respuesta :

Answer:

In Python:

def main():

   repeat = True

   while(repeat):

       feet = int(input("Feet: "))

       inch = int(input("Inch: "))

       Convert(feet,inch)

       again = int(input("Press 1 to tryagain: "))

       if again == 1:

           repeat = True

       else:

           repeat = False

       

def Convert(feet,inch):

   meter = 0.3048 * feet

   cm = (inch/12) * 0.3048 * 100

   printOut(meter,cm)

def printOut(meter,cm):

   print("Meter: %.3f"%(meter))

   print("Centimeter : %.3f"%(cm))

   

if __name__ == "__main__":

   main()

Explanation:

The main function is defined here (used for input)

def main():

This sets boolean variable repeat to true

   repeat = True

This loop is repeated until repeat = false

   while(repeat):

The next two lines get the input from the user

       feet = int(input("Feet: "))

       inch = int(input("Inch: "))

This calls the convert function to convert the units respectively

       Convert(feet,inch)

This prompts the user to tryagain

       again = int(input("Press 1 to tryagain: "))

If yes, the loop is repeated. Otherwise, the program ends

       if again == 1:

           repeat = True

       else:

           repeat = False

The Convert method begins here (used for calculation)

def Convert(feet,inch):

This converts feet to meter

   meter = 0.3048 * feet

This converts inch to centimeter

   cm = (inch/12) * 0.3048 * 100

This calls the printOut function

   printOut(meter,cm)

The printOut method begins here (used for printing)

def printOut(meter,cm):

These print the converted units

   print("Meter: %.3f"%(meter))

   print("Centimeter : %.3f"%(cm))

   

The main function is called here

if __name__ == "__main__":

   main()