Search code examples
pythonif-statementwhile-loopuser-input

While loop based on if statements looping but not checking


Im trying to make a way for the user to check all of their individual stats when asking for them, and this is how I'm doing it. The problem is, when I run it, I can use one of the if functions or the while condition (making the program end), but after that I have no clue what happens. It obviously keeps looping but the program doesn't end and I can't use the other if functions, any thoughts?

print("ask about your stats")
userInput = input()
while userInput != "Pass":
    if userInput == "Stats":
        print(billyMays)
    elif userInput == "Health":
        print(health)
    elif userInput == "Hunger":
        print(hunger)
    elif userInput == "Voice":
        print(voice)
    else:
        pass
    userInput = None
print("goodbye")

Solution

  • After you assign userInput = None, the while condition remains True forever and the body of the loop effectively does nothing.