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
<em> feet = int(input("Feet: "))
</em>
<em> inch = int(input("Inch: "))
</em>
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
<em> if again == 1:
</em>
<em> repeat = True
</em>
<em> else:
</em>
<em> repeat = False
</em>
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
<em> print("Meter: %.3f"%(meter))
</em>
<em> print("Centimeter : %.3f"%(cm))
</em>
The main function is called here
<em>if __name__ == "__main__":
</em>
<em> main()
</em>