简体   繁体   English

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

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

I'm currently working on a text based game for a school project. 我目前正在为学校项目开发基于文本的游戏。 I keep getting an invalid syntax error for the part that says 'reply'. 对于显示“答复”的部分,我一直收到无效的语法错误。 Would you know why this may be? 你知道为什么会这样吗? I've used this method a lot throughout the game and this is the first time i'm getting this error. 我在整个游戏中都使用过这种方法,这是我第一次遇到此错误。

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")

At this line 在这条线

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

you should enclose the string in two double quotes and then close with a final parenthesis: 您应该将字符串用两个双引号引起来,然后用最后的括号括起来:

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

In this part of the code: 在这部分代码中:

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

You aren't ending your print statement or your string, unfinished work I suppose. 您不会结束打印语句或字符串,我想这是未完成的工作。 Therefore, the rest of the code is treated as a string, the string has no end and the print statement has no closing parentheses. 因此,其余代码被视为一个字符串,该字符串没有结尾,并且print语句没有右括号。

Programmers make these mistakes all the time but as you get more and more experienced you need to catch these mistakes. 程序员总是会犯这些错误,但是随着您越来越有经验,您需要抓住这些错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM