how to loop if else condition?

Viewed 38

How do I loop to input("(K)g or (L)bs: ") when L or K is not selected?

weight = int(input("Weight: "))
unit = input("(K)g or (L)bs: ")

if unit.upper() == "K":
    print("Weight in Kg: " + str(weight))
elif unit.upper() == "L":
    print("Weight in Lbs: " + str(weight*2.20462262185))
else:
1 Answers

Add a while loop

weight = int(input("Weight: "))

while True:
    unit = input("(K)g or (L)bs: ")

    if unit.upper() == "K":
        print("Weight in Kg: " + str(weight))
        break
    elif unit.upper() == "L":
        print("Weight in Lbs: " + str(weight * 2.20462262185))
        break
Related