-1

My understanding of the following code is that if user_input does not equal "up" or "down", it should keep looping. But if it does equal "up" or "down", then it changes valid_move to True and stops looping. But no matter what the user input is, it always prints ("Invalid entry") and never gets out of the while loop.

valid_move = False

while not valid_move:
    user_input = input("enter up or down")
        if user_input != "up" or user_input != "down"):
            print("invalid entry")

        else:
            valid_move = True
            print(user_input)

Why is that?

2 Answers2

1

The mistake is your condition, instead of:

if user_input != "up" or user_input != "down")

Use:

if user_input != "up" and user_input != "down")
RMPR
  • 3,368
  • 4
  • 19
  • 31
1

Use "and" instead of "or" in your if statement as said by