PLEASE DO NOT COPY PASTE FROM CHEGG/OTHERWISE I'LL REPORT YOU OR GIVE OU A DISLIKE
#1 Problem A. (8 points) Hero Class We'll start by creating an Hero class, which is a basic template class for all of the specialization classes to build on using inheritance. The Hero class should have the following methods: Constructor: The Hero class constructor should have the following signature: _init_(self, name, level, strength, magic) where name (the name of the Hero) should be a string and level, strength, and magic should be integers that represent the Hero's ability levels. The constructor should create instance variables to store the value of each of these arguments (self.name, self.level, self strength, and self.magic, respectively), along with two more instance variables: self.HP, an integer representing the Hero's remaining Hit Points, which should be initialized to the Hero's level multiplied by 5. self.hidden, a boolean representing whether the Hero is currently hiding, which should be initialized to False. _repr_(self) You must override the repr() method (similar to the str() method, except that it also changes what is output when you pass the object directly to the interpreter) for the Hero class so that it returns a string of the format:
HP Be sure to match the spacing and format of the above string exactly or you will fail test cases and lose points (note that the angled brackets are not part of the string itself, but indicate where you should substitute in the actual name and hit points of your Hero). Note that changing_repr_automatically changes the behavior of str() as well. See the sample output below for an example. attack(self, target) The attack method takes as a parameter another Hero object target and does the following: If the target is hidden, then this method should print the string: can't see attacks damage = Example: (italic text is printed, bold text is returned) >>> thog - Hero("Thog", 5, 3, 2) >>> print(thog.level, thog.strength, thog.magic) 532 >>> repr(thog) 'Thog: 25 HP >>> goku = Hero("Goku", 9001, 20, 7) >>> str(goku) 'Goku: 45005 HP >>> goku. hidden = True >>> thog attack(goku) Thog can't see Goku >>> goku. attack(thog) Goku attacks Thog for 23 damage >>>print (thog) Thog: 2 HP >>> goku.attack(thog) Goku attacks Thog for 23 damage >>> print(thog) Thog: -21 HP #1 Problem A. (8 points) Hero Class We'll start by creating an Hero class, which is a basic template class for all of the specialization classes to build on using inheritance. The Hero class should have the following methods: Constructor: The Hero class constructor should have the following signature: _init_(self, name, level, strength, magic) where name (the name of the Hero) should be a string and level, strength, and magic should be integers that represent the Hero's ability levels. The constructor should create instance variables to store the value of each of these arguments (self.name, self.level, self strength, and self.magic, respectively), along with two more instance variables: self.HP, an integer representing the Hero's remaining Hit Points, which should be initialized to the Hero's level multiplied by 5. self.hidden, a boolean representing whether the Hero is currently hiding, which should be initialized to False. _repr_(self) You must override the repr() method (similar to the str() method, except that it also changes what is output when you pass the object directly to the interpreter) for the Hero class so that it returns a string of the format: HP Be sure to match the spacing and format of the above string exactly or you will fail test cases and lose points (note that the angled brackets are not part of the string itself, but indicate where you should substitute in the actual name and hit points of your Hero). Note that changing_repr_automatically changes the behavior of str() as well. See the sample output below for an example. attack(self, target) The attack method takes as a parameter another Hero object target and does the following: If the target is hidden, then this method should print the string: can't see attacks damage = Example: (italic text is printed, bold text is returned) >>> thog - Hero("Thog", 5, 3, 2) >>> print(thog.level, thog.strength, thog.magic) 532 >>> repr(thog) 'Thog: 25 HP >>> goku = Hero("Goku", 9001, 20, 7) >>> str(goku) 'Goku: 45005 HP >>> goku. hidden = True >>> thog attack(goku) Thog can't see Goku >>> goku. attack(thog) Goku attacks Thog for 23 damage >>>print (thog) Thog: 2 HP >>> goku.attack(thog) Goku attacks Thog for 23 damage >>> print(thog) Thog: -21 HP