-1

For my studies, I have begun to learn the Python Programming Language.

Fairly new to programming and having some trouble understanding why this won't work.

while compReady == False: 
    compAI = input("Which strategy for the computer [1,2,3]? ")
    if compAI == "1" or "2" or "3":
        compReady = True
    elif compAI != "1" or "2" or "3":
        print("Please enter either 1, 2, or 3.")

The problem I have is that no matter what is inputted into compAI, it runs through the 'if' statement. Any help is appreciated, thanks.

  • Hint: what if you reordered the conditions (`or` is commutative) so that you had `if "2" or "3" or compAI == "1":`? – Henry Woody Oct 16 '21 at 03:15

1 Answers1

0

if condition should be written as ..

 if compAI == ("1" or "2" or "3"):

In your code, Python interpreter will treat "2" and "3" as true. Please note it is not compared with compAI as per if statement syntax.

Digital_Reality
  • 4,488
  • 1
  • 29
  • 31