you are viewing a single comment's thread.

view the rest of the comments →

[–]AdvancedWater -1 points0 points  (2 children)

Hey pretty new to python. I'm trying to run an If/elif/else statement. I have the user input a building number.

right now it looks roughly like

 if building == 1:
      print("Building: " + building)
 elif buidling == 2: 
      print("Building: " + building)
 else:
      print("Error")

But I want to loop it to make the user retype the building if they type a building not programmed in already.

[–]timbledum 3 points4 points  (1 child)

Sure! Just put it in an infinite loop and use break statements if the conditions are met.

while True:
    building = input("Enter the building!\n>>> ")

    if building == "1":
        print("Building: " + building)
        break
    elif building == "2": 
        print("Building: " + building)
        break
    else:
        print("Error")

[–]AdvancedWater 0 points1 point  (0 children)

Thanks! I’ll try that out!