python - 输入给出未知的语法错误 - 其他一切正常
问题描述
我正在开发一个 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')
解决方案
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')
您必须尝试通过阅读错误描述来解决您的错误。
推荐阅读
- azure - 网络错误导致媒体下载中途失败 azure 媒体服务
- angular - 角度、材质侧导航和粘性工具栏
- javascript - 匹配任何后跟非数字的字符
- java - MainActivity.java:使用或覆盖已弃用的 API。使用 -Xlint:deprecation 重新编译以获取详细信息
- python - 如何从字符串列表中随机选择不包括数字的标记?
- sql - EXcel 宏不返回 SQL
- .net - 使用文本框的 For 循环
- swift - 一个删除线样式中的 Swift 多个标签
- psql - 需要返回位于未来 1 个月或更长时间的日期范围(通常为 1 周)内的 MAX(DATE)
- javascript - 从父组件切换布尔状态