这是我正在使用的代码:
def EnemyAttack():
print("The enemy",enemy, "Attacked!")
HP - EnemyAttack
if HP < 0 or HP == 0:
print("You Were torn to pieces by the",enemy,".")
else:
print("You managed to withstand the attack by the",enemy, "It growls in
frustration.")
BattleChoice()
...以及运行时收到的错误:
Traceback(最近一次调用最后一次):文件“python”,第83行,in 文件“python”,第62行,在EnemyAttack TypeError中: 不支持的操作数类型 - :'int'和'function'
答案 0 :(得分:0)
查看代码的第3行:
HP - EnemyAttack
您的HP
变量是一个整数,EnemyAttack
是一个不返回数字的函数。如果您的EnemyAttack
会返回一个号码,则可以使用:
HP -= EnemyAttack()
根据HP
返回的数字减少EnemyAttack
。