python 3中带有if语句的奇怪SyntaxError?

时间:2019-11-12 03:27:46

标签: python-3.x if-statement syntax-error

我一直在尝试为游戏运行代码,但是在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

我希望它可以结束,并且程序可以正常运行。

1 个答案:

答案 0 :(得分:0)

您是否使用固定空格进行缩进?

while conditions:
    statements
    if conditions:
        statements

似乎您没有使用 if

的缩进