0

Creating nested conditional statements but when i run this and the first boolean is false, the next input prompt doesn't come up, please help

bird_names="magpie pigeon dove"
bird_guess=input("venture a guess about the bird names we have stored: ")
if bird_guess in bird_names==False:
    bird_guess=input("venture a guess about the bird names we have stored: ")
    if bird_guess in bird_names==False:
        bird_guess=input("try again ")
        if bird_guess in bird_names==False:
            print("you're out of tries")
        else:
            print("third time lucky")
    else:
        print("second time lucky")
else:
    print("first time lucky")
Adit Vaddi
  • 13
  • 1

1 Answers1

3

The issue is operator chaining. bird_guess in bird_names==False is evaluated as:

(bird_guess in bird_names) and (bird_names == False)

Since the second expression always evaluates to False, the condition is never satisfied. You can use parentheses to avoid the problem:

(bird_guess in bird_names) == False

More idiomatic is to use the purpose-built not in operator:

bird_guess not in bird_names
jpp
  • 159,742
  • 34
  • 281
  • 339