Unsupported Operand For 3 Instances Of Two Classes And One Method?
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
Solution 1:
In the getHit()
method you are passing the arguments:
hp
attack
defence
but when you call it in enemyUnit.getHit(enemyUnit, tackle, unit)
you are passing enemyUnit
which is an object of the Pokemon
class. This causes the error.
You may want to pass the correct parameters in:
enemyUnit.getHit(...) # Correct the parameters
Edit:
I think the best idea would be to implement the getHit()
method like this:
defgetHit(self, other, move):
self.hp -= move.damage * other.attack / self.defence
printstr(self.hp)
and call it with:
enemyUnit.getHit(unit, tackle)
Note that you were passing hp
and attack
, which are attributes of Pokemon
. You can use them by just calling obj.hp
and obj.attack
.
Post a Comment for "Unsupported Operand For 3 Instances Of Two Classes And One Method?"