0

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:
Shredz
  • 15
  • 4

1 Answers1

1

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
yangjie
  • 6,619
  • 1
  • 33
  • 40