== op无法正常工作,不知道为什么

时间:2019-03-16 20:56:20

标签: python

已解决

问题是if语句在“ birds_guess in bird == true”语句中两次检查了True。因此将其更改为“ birds_guess in birds”即可解决问题。

我正在运行以下代码:

def guess_bird():
    birds = "Parrot, Owl, Penguin, Emu"
    bird_guess = input("Guess a bird. ")
    print(bird_guess in birds)
    if bird_guess in birds == True:
        print("Correct! First try. ")
    else:
        print("incorrect. Try again. ")
        bird_guess = input("Guess a bird. ")
        if bird_guess in birds == True:
            print("Correct! Second try. ")
        else:
            print("incorrect. Try again. ")
            bird_guess = input("Guess a bird. ")
            if bird_guess in birds == True:
                print("Correct! Third try. ")
            else:
                print("Incorrect. that was the last try you get! ")
guess_bird()

运行此命令时,输出为

Guess a bird. Emu     
True    
Incorrect. Try again.   
Guess a bird. _

我希望它能像saying在鸟中并且if语句退出那样运行。我不知道为什么这样运行,请帮助

我在其中编写代码的图像。 I also didn't import any libraries.

0 个答案:

没有答案