Почему я получаю синтаксическую ошибку при использовании ввода в выражении elif? - PullRequest
0 голосов
/ 02 марта 2019

В настоящее время я работаю над текстовой игрой для школьного проекта.Я продолжаю получать неверную синтаксическую ошибку для части, которая говорит «ответ».Знаете ли вы, почему это может быть?Я часто использовал этот метод на протяжении всей игры, и я впервые получаю эту ошибку.

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

Ответы [ 2 ]

0 голосов
/ 02 марта 2019

В этой части кода:

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

Вы не заканчиваете свое утверждение печати или свою строку, я полагаю, незаконченная работа.Поэтому остальная часть кода обрабатывается как строка, строка не имеет конца, а оператор print не имеет закрывающих скобок.

Программисты постоянно совершают эти ошибки, но по мере того, как вы становитесь все более опытными, вам нужночтобы поймать эти ошибки.

0 голосов
/ 02 марта 2019

В этой строке

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

вы должны заключить строку в две двойные кавычки, а затем закрыть с заключительными скобками:

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