Instructions: Exercise 1 Template: from fighters import * if…
Question Answered step-by-step Instructions: Exercise 1 Template: from fighters import * if… Instructions:Image transcription textExamine the starter code in the file fighterspv and locatethe superclass Fighter. a. How manv class attributes doesthe Fighter class have? Answer: __ You can t… Show more… Show moreImage transcription textExercise 2: Alien versus Predator (2 pts) Answer this question in the filesExercise2 . py and fighters . py a. Each fighter’s success rate starts at50%. self. success_rate = 50 # probability of an attack bein… Show more… Show moreExercise 1 Template:from fighters import * if __name__ == “__main__”:print(“nEXERCISE 1”)# variables to test if they are class or instance variables.variables = [‘sort’, ‘max’, ‘__main__’, ‘_ID’, ‘ID’, ‘category’, ‘name’, ‘hit_points’, ‘damage’, ‘nope’] # a. Check if each variable in the list is a class variable.print(“nna. Check if each variable in the list is a class variable.”) for var in variables:# add code here.pass # b. Check if each variable in the list is an instance variable.print(“nnb. Check if each variable in the list is an instance variable.”) fighter = Fighter(100, 10) # an instance of a Fighter for var in variables:# add code here.pass # c. use an if/elif/else block to test if a variable is a class variable or an instance variable.print(“nnc. Check if each variable in the list is a class or instance variable.”) for var in variables:# add code here.pass Exercise 2 Template:class ANSI(object):MAGENTA = ’33[95m’CYAN = ’33[96m’DARKCYAN = ’33[36m’BLUE = ’33[94m’GREEN = ’33[92m’YELLOW = ’33[93m’RED = ’33[91m’GREY = ’33[90m’BLACK = ’33[30m’BOLD = ’33[1m’UNDERLINE = ’33[4m’END = ’33[0m’ class Fighter:category = “Fighter” # class attribute/variable_ID = 0 # this class variable is PROTECTED with one underscore def __init__(self, hit_points=100, damage=10):Fighter._ID += 1 # increment the protected class variableself.ID = Fighter._ID # this instance variable is publicself.fullID = “Fighter:” + (“%04d” % self.ID)self.name = “Anonymous Fighter”self.hit_points = hit_points # the health of the fighter measured in hit points.self.damage = damage # the damage dealt by the fighter when it attacks an enemyself.success_rate = 50 # probability of an attack being successful# add code to replace 50 with a random integer from 25 to 75 self.dead = (self.hit_points == 0) def attack(self, target):if self.dead: # cannot attack if deadreturnif random.randint(1, 100) <= self.success_rate: # probability attack is successful# the target takes damage heretarget.hit_points = max(target.hit_points - self.damage, 0) # min is zerotarget.dead = (target.hit_points == 0) # update death status of target# add code to increase success_rate by 2. Use min() to assure this does not exceed 100%# add code here def __str__(self):if self.dead:return ANSI.RED + ANSI.BOLD + "DEAD" + ' ' * 8 + ANSI.ENDelse:return str("%04d" % self.hit_points) def regenerate(self):# Reset the hit points to 100 here.# Reset the dead attribute to Falsepass def death_match(self, other):print((ANSI.BOLD + "%-12s|%-12s" + ANSI.END) % (self.name, other.name))print("%-12s|%-12s" % (self, other))while not (self.dead or other.dead):# add two lines of code so that each combatant attacks the opponenttime.sleep(0.2)print("%-12s|%-12s" % (self, other))victor = ""if self.dead:victor = otherelse:victor = selfprint("nThe victor of this death match is " + victor.name)print("The victor's success rate is now ", victor.success_rate) Answer template:Image transcription textExercise 1: Class Variables and Instance Variables (2 pts)a. How many class attributes does the Fighter class have?Answer: b. Paste your combined 1 f/el i f/else ... Show more... Show more Computer Science Engineering & Technology Python Programming ENGR 203 Share QuestionEmailCopy link Comments (0)


