Question
Along with the Pokemon parent class, we have also provided several subclasses. Write another method in the parent class that will be inherited by the
Along with the Pokemon parent class, we have also provided several subclasses. Write another method in the parent class that will be inherited by the subclasses. Call it opponent. It should return which type of pokemon the current type is weak and strong against, as a tuple. Grass is weak against Fire and strong against Water Ghost is weak against Dark and strong against Psychic Fire is weak against Water and strong against Grass Flying is weak against Electric and strong against Fighting For example, if the p_type of the subclass is 'Grass', .opponent() should return the tuple ('Fire', 'Water')
class Pokemon(): attack = 12 defense = 10 health = 15 p_type = "Normal"
def __init__(self, name,level = 5): self.name = name self.level = level self.weak = "Normal" self.strong = "Normal"
def train(self): self.update() self.attack_up() self.defense_up() self.health_up() self.level = self.level + 1 if self.level%self.evolve == 0: return self.level, "Evolved!" else: return self.level
def attack_up(self): self.attack = self.attack + self.attack_boost return self.attack
def defense_up(self): self.defense = self.defense + self.defense_boost return self.defense
def health_up(self): self.health = self.health + self.health_boost return self.health
def update(self): self.health_boost = 5 self.attack_boost = 3 self.defense_boost = 2 self.evolve = 10
def __str__(self): self.update() return "Pokemon name: {}, Type: {}, Level: {}".format(self.name, self.p_type, self.level)
class Grass_Pokemon(Pokemon): attack = 15 defense = 14 health = 12 p_type = "Grass"
def update(self): self.health_boost = 6 self.attack_boost = 2 self.defense_boost = 3 self.evolve = 12
class Ghost_Pokemon(Pokemon): p_type = "Ghost"
def update(self): self.health_boost = 3 self.attack_boost = 4 self.defense_boost = 3
class Fire_Pokemon(Pokemon): p_type = "Fire"
class Flying_Pokemon(Pokemon): p_type = "Flying"
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started