HP - EnemyAttack向我抛出错误:L

时间:2018-01-19 10:36:44

标签: python

这是我正在使用的代码:

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'

1 个答案:

答案 0 :(得分:0)

查看代码的第3行:

HP - EnemyAttack  

您的HP变量是一个整数,EnemyAttack是一个不返回数字的函数。如果您的EnemyAttack会返回一个号码,则可以使用:

HP -= EnemyAttack()

根据HP返回的数字减少EnemyAttack