Python:变量名称是'语法错误'

时间:2013-10-18 02:25:31

标签: python variables python-2.7 syntax error-handling

我一直致力于一个小型的战斗模拟程序,它具有损坏,健康和防御以及其他东西(只是为了好玩),但我遇到了这种'语法错误'。语法错误是由enemystr = str(enemydamage)引起的。我尝试删除它,但它只是说下面的print语句是语法错误。

def enemyattack():
    enemyrandompick = random.randint(1, 4)
    if enemyrandompick == 1:
        enemydamage = (random.randint(1, 3) * (enemyattack - (defense * 1.25))
        enemystr = str(enemydamage)
        print "The enemy's attack hits you and takes away " + enemystr , "health, leaving you with" + str(int(health))

2 个答案:

答案 0 :(得分:2)

这一行有不匹配的括号:

enemydamage = (random.randint(1, 3) * (enemyattack - (defense * 1.25)))
#                                                                     ^ Missing closing paranthesis

答案 1 :(得分:-1)

而且我认为你没有宣布变量'健康'。

`print "The enemy's attack hits you and takes away " + enemystr , "health, leaving you with" + str(int(health))
                                                                                                         ^
`