Can anyone help as to why my while loop isn’t working?
It’s forcing the user to select either 1, 2 or 3, and not letting them proceed, however regardless of whether you put in 1, 2 or 3, it always says that you’ve entered a different number, and so says “Please choose level 1, 2 or 3”
level = input("Enter your level by typing 1, 2 or 3\n")
int(level)
levelSelect = 1
while levelSelect == 1:
if level != int(1) or level != 2 or level != 3:
level = input("Please choose level 1, 2 or 3\n")
int(level)
else:
print("You have selected level", level)
levelSelect = 0
The line
int(level)doesn’t do what you think it does. It creates an integer from a string and returns it. It does not operate in place. Because of this, when you get to yourifstatement, you’re comparing a string to integers which is always unequal.You probably want:
As a side note, the condition could also be written using the
inoperator: