为什么在 elif 语句中使用输入会出现语法错误?

Why am I getting a syntax error for using an input within an elif statement?

我目前正在为一个学校项目开发基于文本的游戏。我一直收到 'reply' 部分的无效语法错误。你知道为什么会这样吗?我在整个游戏过程中经常使用这种方法,这是我第一次遇到这个错误。

print("You decide it's time to look for a way out of this place. You consider travelling upstream to investigate where the wallet came from. You also remember being told that all rivers will eventually lead to a town or village.")
direction = input("Do you travel a)upstream or b)downstream? >")
if direction == "upstream" or direction == "Upstream" or direction == "Up" or direction == "up" or direction == "travel upstream" or direction == "Travel upstream":
      print("You travel upstream")
elif direction == "downstream" or direction == "Downstream" or direction == "Down" or direction == "down" or direction == "travel downstream" or direction == "Travel Downstream":                                        
      print("You travel downstream. You walk for hours but the river does not lead anywhere. It gets dark and you can no longer find your way. You decide to rest until morning.")
      print("You are suddenly woken from your sleep by a familiar voice. It's your", spouse+"!")
      print(spouse_name.upper()+":", '"'+name_f+"!?",'What are you doing here?'
      reply = input("Enter 1 for 'What are you doing here??' Enter 2 for 'I don't know, I just woke up here' >")
      if reply == '1':
            print(name_f.upper()+':',"What are you doing here??")
            print(name_f.upper()+':',"I
      elif reply == '2':
            print(name_f.upper()+':',"I don't know, I just woke up here")
            print(name_f.upper()+':',"I don't remember anything, I don't remember how I got here"
      print(spouse_name.upper()+":", "How are you still alive?"
      print(name_f.upper()=':', spouse_name+',','what are you talking about??')
      print("before you have time to realise what's going on,", spouse,"pulls out a gun and shoots you in the head")
      print("GAME OVER")

在这一行

print(name_f.upper()+':',"I

您应该将字符串括在两个双引号中,然后用最后一个括号结束:

print(name_f.upper()+':',"I")

在这部分代码中:

 print(name_f.upper()+':',"I
 elif reply == '2':

你没有结束你的打印语句或你的字符串,我想是未完成的工作。 因此,其余代码被视为字符串,字符串没有结尾,打印语句没有右括号。

程序员总是会犯这些错误,但随着您的经验越来越丰富,您需要抓住这些错误。