首页 > 解决方案 > 输入给出未知的语法错误 - 其他一切正常

问题描述

我正在开发一个 RPG,它给了我未知的错误。当我运行它时,它只是说语法错误,但我找不到任何错误。谢谢!

name=str(input('Enter you name here:'))
adjective = str(input('Use one adjective to describe yourself:'))
rpg_class = input('Please choose your class. S = Soldier. W = Wizard. R = Rogue:'):
  if rpg_class=='S' or rpg_class=='s':
    print('\n')
    soldierdecisionone=input('You are a high esteemed soldier named ' + str(name) + '. Your city has been having frequent attacks from a mysterious beast in the middle of the night. You decide to explore into the wild to find out more. As you exit the city, you come to a fork in the road. Which way to you head? left/right'):
      if soldierdecisionone=='Left' or soldierdecisionone=='left':
        print('\n')
        soldierattackorc=input('You head left towards the woods. Just as you enter, a large orc jumps out from behind a bush and confronts you. It is at least twice your size. What do you do? attack/defend'):
          if soldierattackorc=='attack' or soldierattackorc=='Attack': print ('You attempted to attack the massive orc. Pretty bad idea, for your sword snaps on his thick hide. The orc beats you with his club until you die. GAME OVER')
          if soldierattackorc=='defend' or soldierattackorc=='Defend': soldierfindfood=input('You block the orc\'s attack with your shield. You run into the foods as fast as you can while he is stunned. As you explore deeper, you start to have aching hunger pains. To your left, you see a bush of white berries. To your right, you see a river surrounded by a few small animals. What do you do? forage/hunt')

标签: pythonpython-3.x

解决方案


rpg_class = input('Please choose your class. S = Soldier. W = Wizard. R = Rogue:'):
  if rpg_class=='S' or rpg_class=='s':

错误就在这里。输入函数不应以 ':' 结尾。此外,它不会创建新块,因此不需要缩进以 if 开头的下一行

语法更正代码

name=str(input('Enter you name here:'))
adjective = str(input('Use one adjective to describe yourself:'))
rpg_class = input('Please choose your class. S = Soldier. W = Wizard. R = Rogue:')
if rpg_class=='S' or rpg_class=='s':
    print('\n')
    soldierdecisionone=input('You are a high esteemed soldier named ' + str(name) + '. Your city has been having frequent attacks from a mysterious beast in the middle of the night. You decide to explore into the wild to find out more. As you exit the city, you come to a fork in the road. Which way to you head? left/right')
    if soldierdecisionone=='Left' or soldierdecisionone=='left':
        print('\n')
        soldierattackorc=input('You head left towards the woods. Just as you enter, a large orc jumps out from behind a bush and confronts you. It is at least twice your size. What do you do? attack/defend')
        if soldierattackorc=='attack' or soldierattackorc=='Attack': print ('You attempted to attack the massive orc. Pretty bad idea, for your sword snaps on his thick hide. The orc beats you with his club until you die. GAME OVER')
        if soldierattackorc=='defend' or soldierattackorc=='Defend': soldierfindfood=input('You block the orc\'s attack with your shield. You run into the foods as fast as you can while he is stunned. As you explore deeper, you start to have aching hunger pains. To your left, you see a bush of white berries. To your right, you see a river surrounded by a few small animals. What do you do? forage/hunt')

您必须尝试通过阅读错误描述来解决您的错误。


推荐阅读