Aug-18-2022, 07:56 PM
Please help me with the below program. My Python is rusty. I'm trying to help my son with the below program. It should return a message like "Pichu (health: 30)", but it only returns nothing. Am I supposed to run a certain function?
What is missing?
What is missing?
class Pokemon(): def __init__(self): self.name = "" self.health = 0 def attack(self, other_pokemon): raise NotImplementedError( "Sorry, all subclasses have to write their own attack function!") class Pichu(Pokemon): def __init__(self): self.name = "Pichu" self.health = 30 def attack(self, other_pokemon): other_pokemon.health -= 2 if other_pokemon.is_alive(): print("Pichu ZAPPED {}, dealing 2 damage [{}]".format( other_pokemon.name, other_pokemon.health)) else: print("Pichu ZAPPED {}, which faints".format(other_pokemon.name)) def is_alive(self): if self.health > 0: return True else: return False return "{} (health: {})".format(self.name, self.health) def __str__(self): pass