I'm trying to get the program to take the hp stat from enemyUnit
, the attack stat from unit
, and the damage stat from tackle
and put them into one math problem in the method getHit()
. this is the code:
class Pokemon(object):
def __init__(self,hp,attack,defence):
self.hp = hp
self.attack = attack
self.defence = defence
def getHit(self,damage,hp,attack):
self.hp -= damage * self.attack/self.defence
print str(self.hp)
class Move(object):
def __init__(self,damage):
self.damage = damage
unit = Pokemon(10,2,3)
enemyUnit = Pokemon(4,2,3)
tackle = Move(3)
enemyUnit.getHit(enemyUnit,tackle,unit)
unfortunately it gives me the error
unsupported operand type(s) for *: 'Pokemon' and 'int'
how do I get it to take all the variables from all instances of each class and put them into one function?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…