Help me understand why it does not loop correctly and how to make the converter a continious loop? What am I doing wrong and how can I fix it? PYTHON
Code
def metric_english ():
print("Select metric units to convert to English equivilant: ")
print("For kilometers type: 1")
print("For meters type: 2")
print("For centimeters type: 3")
print("\n")
metEng = input("Choose metric units to convert (1, 2, 3): ")
print("\n")
print("Convert to which English units: ")
print("For miles type: 1")
print("For feet type: 2")
print("For inches type: 3")
print("\n")
metEng1 = input("Choose target English units (1, 2, 3): ")
print("\n")
if (metEng and metEng1 == 1):
num1 = input("Enter the number of miles to conver to kilometers: ")
convert2 = num1 * 0.62137
print("RESULT: ", num1, " kilometers = ", convert2, " miles")
elif (metEng and metEng1 == 2):
num1 = input("Enter the number of feet to convert to meters: ")
convert2 = num1 * 0.3048
print("RESULT: ", num1, "meters = ", convert2, " feet")
elif (metEng and metEng1 == 3):
num1 = input("Enter the number of inches to convert to centimeters: ")
convert2 = num1 * 2.54
print("RESULT: ", num1, "centimeters = ", convert2, " feet")
elif (metEng == 1 and metEng1 == 2):
num1 = input("Enter the number of feet to conver to kilometers: ")
convert2 = num1 * 1000
print("RESULT: ", num1, " meters = ", convert2, " miles")
elif (metEng == 1 and metEng1 ==3):
num1 = input("Enter the number of inches to conver to kilometers: ")
convert2 = num1 * 100000
print("RESULT: ", num1, " centimeters = ", convert2, " miles")
elif (metEng == 2 and metEng1 == 1):
num1 = input("Enter the number of miles to convert to meters: ")
convert2 = num1 * 0.0003048
print("RESULT: ", num1, " kilometers = ", convert2, "miles ")
elif (metEng == 3 and metEng1 == 2):
num1 = input("Enter the number of feet to conver to centimeters: ")
convert2 = num1 * 0.0254
print("RESULT: ", num1, " meters = ", convert2, " inches")
elif (metEng == 2 and metEng1 == 3):
num1 = input("Enter the number of inches to conver to meters: ")
convert2 = num1 * 30.48
print("RESULT: ", num1, " centimeters = ", convert2, " feet")
elif (metEng == 3 and metEng1 == 1):
num1 = input("Enter the number of miles to convert to centimeters: ")
convert2 = num1 * 2.54 #add exponent
print("RESULT: ", num1, " kilometers = ", convert2, " inches")
def main ():
print("\nWelcome to the English/Metric conversion utility.")
print("This utility allows you to convert between English units (miles, feet, inches) and metric units (kilometers, metters, centimeters). ")
print("\n")
print("--------------------------------------------------------")
print("\n")
print("Which direction would you like to convert: ")
print("For English Metric type: 1")
print("For Metric to English type: 2")
print("To Quit type: 3")
print("\n")
ans = int(input("Input your answer (1, 2, 3): "))
while ans <= 3:
if (ans == 1):
english_metric()
if (ans == 2):
metric_english()
if (ans == 3):
print("Thanks for using our converter. Goodbye!")
print("\n")
break
else:
print(errorMessage)
main()