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()
Step-by-step 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()