python - Python : Variable name is 'syntax error'

标签 python variables python-2.7 syntax error-handling

我一直在研究一个小型战斗模拟程序,其中包含伤害,健康和防御以及其他东西(只是为了好玩),但是遇到了这个“语法错误”。语法错误是由敌人str = 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))

最佳答案

此行上的括号不匹配:

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

关于python - Python : Variable name is 'syntax error' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19440588/

相关文章:

bash - 声明不是有效的标识符 bash

javascript - 使用 less.js 获取更少的变量列表

JavaScript:一个变量可以有多个值吗?

python-2.7 - tkinter 进度条 - 链接到功能?

python - 我怎样才能去除这个二值图像中的噪声并平滑图像-openCV

python 暂停 pexpect.spawn 及其使用的设备

python - 在 django slug 字段中使用外语不起作用

python - pytest 的 addoptions 和动态参数化测试装置的问题

python-2.7 - 什么时候在 spark 数据帧上使用 persist() 性能不实用?

Python 最小样板类初始化