python-3.x - python 3中if语句的奇怪语法错误?
问题描述
我一直在尝试运行游戏代码,但我的 if 语句不断收到 SyntaxError,并且在终端中,它一直指向冒号。我不知道为什么,我只是一个初学者,所以我理解这是否很奇怪。请注意,代码没有缩进问题,只是复制和粘贴。
我试过使用整数和字符串,但没有任何效果。我不知道该怎么办。
while monster.enemyhealth>0:
print ("[Your Turn]")
print ("(1) Smash")
print ("(2) "+player.secondary_attack)
print ("(3) "+player.tertiary_attack)
print ("(4) Backpack")
print ("(5) Escape Battle")
battleinput=int(input(">>>")
if battleinput==1:
monster.enemyhealth-player.primary_attack.damage=monster.enemyhealth
print ("You did "+smash.damamge+" to the monster!")
player.powerpoints-player.primary_attack.powerpointcost=player.powerpoints
player.health-monster.attackpower=player.health
print ("The monster did "+str(monster.attackpower)+" to you!")
这就是错误:
File main.py, line 140
if battleinput==1:
↑
SyntaxError: invalid syntax
我希望它会结束,并且程序可以正常运行。
解决方案
您是否使用固定空格进行缩进?
while conditions:
statements
if conditions:
statements
似乎你在使用if的地方没有真正的缩进
推荐阅读
- php - 事件代码点火器的完成日期状态
- r - 基于另一个变量的 R dplyr 日期过滤器
- c - 如何通过在数组中一次取 2 个项目来将权重添加到麻袋中?
- javascript - 如何在 forEach 中使用箭头函数?
- python - flask ['GET'] 方法总是返回
用 pytest - javascript - 将对象投射到打字稿中的模型
- python - 使用 spaCy 进行否定和依赖解析
- python - 查询 Python fnmatch 模块?
- json - 如何将 JSON 令牌保存到用户默认值,然后在不同的视图中使用它?斯威夫特 4
- java - 当我在 android studio 中打开视频时出现问题