Question: Language= python Consider the class Pokemon In (): Remember to run this cell DO NOT DELETE OR MODIFY THIS CELL class Pokemon: def _init__(self, species,

Language= python

Language= python Consider the class Pokemon In (): Remember to run thiscell DO NOT DELETE OR MODIFY THIS CELL class Pokemon: def _init__(self,

Consider the class Pokemon In (): Remember to run this cell DO NOT DELETE OR MODIFY THIS CELL class Pokemon: def _init__(self, species, level, health): self. species = species self.level = level self health = health Write a subclass MyPokemon. For full credit, your subclass should not contain species. level or health attributes/fields of its own; it should rely on those in the superclass This class creates objects that can be iterated over using a for loop. The following should work: p = MyPokemon ("Pikachu", 10, 3) for field in p: print(Field) should print the values of all three fields: Pikachu 10 3 MyPokenon has a method train().which increases the level field by 1. The following should work: >>> p = MyPokemon ("Pikachu", 10, 3) >>> print("before train(), level =", p.level) before traino), level = 10 >>> p.train() >>> print("after train(), level =", p.level) after train(), level = 11 Overload the operator > by defining a _gt_method so that we can compare the levels of two MyPokemon objects. For the following two MyPokemon objects A and B. B > A returns True because the level of B is greater than the level of A. >>> A = MyPokemon ("Pikachu", 18, 3) >>> B = MyPokemon ("Charmander", 12, 3) >>> print(B > A) True >>> print (A > B) False MyPokenon also has a method attack() that simulates an attack from a My Pokemon object to another. The attack causes 1 point damage to the target's health field and prints a message about the attack. If the health field of the target is zero before the attack, raise a RuntimeError exception and print an error message "The target Pokemon has lost all health points". The following should work: >>> A = MyPokemon ("Pikachu", 10, 2) >>> B = MyPokemon ("Charmander", 12, 1) >>> A.attack (B) Pikachu attacks Charmander doing 1 danage >>> print(B.health) >>> try: A.attack(0) except RuntimeError as e: print(e) The target Pokemon has lost all health points In (): put your code here Test your class using the code below. It should print the values in all three fields twice In (): 4 test your code here # DO NOT DELETE P = MyPokemon("Pikachu", 10, 3) for field in p: print(field) for field in p: print(field) Run the test cell below as well. The result should be before train(), level = 10 after train(), level = 11 Pikachu attacks Charmander doing 1 damage Pikachu attacks Charmander doing 1 damage Pikachu attacks Charmander doing 1 damage The target Pokemon has lost all health points In (): 4 test your code here 4 DO NOT DELETE A = MyPokemon ("Pikachu", 10, 3) B = MyPokemon("Charmander", 10, 3) print("before train(), level =", A.level) A. train() print("after train(), level =", A. level) if A > B: while True: try: A.attack(B) except RuntimeError as e: print(e) break In ()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!