Python 如何创建嵌套函数
我为猜鸟游戏定义了以下代码Python 如何创建嵌套函数,python,Python,我为猜鸟游戏定义了以下代码 print("Hello, welcome to the guess the bird game! You can guess 3 times. GOOD LUCK!") bird = "robin" guess_bird = input('First try to guess the bird, please fill in your answer:') if guess_bird == bird: print("Congratulations, you
print("Hello, welcome to the guess the bird game! You can guess 3 times. GOOD LUCK!")
bird = "robin"
guess_bird = input('First try to guess the bird, please fill in your answer:')
if guess_bird == bird:
print("Congratulations, you have it right!")
else:
guess_bird = input("Unfortunately.. Once again, don't give up!"
if guess_bird == bird:
print("Congratulations, you have it right!")
else:
guess_bird = input("Last try to guess the bird, you can do it!")
if guess_bird == bird:
print("Congratulations, you have it right!")
else:
print("Sorry, no more tries...")
然而,我得到一个错误。。。我怎样才能解决这个问题?错误是:
File "<ipython-input-6-787643515908>", line 12
if guess_bird == bird:
^
SyntaxError: invalid syntax
您在guess\u bird=input行中缺少一个右括号,很遗憾。。再一次,不要放弃 猜一猜鸟=输入不幸。。再一次,不要放弃!那行应该有一个结束符。它试图在要输入的参数中包含if guess_bird==bird:。缺少一个闭合括号 你在哪里写的
guess_bird = input("Unfortunately.. Once again, don't give up!"
它应该写为
guess_bird = input("Unfortunately.. Once again, don't give up!") #add the ')' at the end
我添加了一个repl.it以供参考
您还没有关闭上一行的括号。标题提到了一个嵌套函数,但代码中似乎没有?