How many class attributes does the fighter class python code…
Question Answered step-by-step How many class attributes does the fighter class python code… How many class attributes does the fighter class python code have(shown below)?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 variable self.ID = Fighter._ID # this instance variable is public self.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 enemy self.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 dead return if random.randint(1, 100) <= self.success_rate: # probability attack is successful # the target takes damage here target.hit_points = max(target.hit_points - self.damage, 0) # min is zero target.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.END else: return str("%04d" % self.hit_points) def regenerate(self): # Reset the hit points to 100 here. # Reset the dead attribute to False pass 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 opponent time.sleep(0.2) print("%-12s|%-12s" % (self, other)) victor = "" if self.dead: victor = other else: victor = self print("nThe victor of this death match is " + victor.name) print("The victor's success rate is now ", victor.success_rate) Computer Science Engineering & Technology Python Programming CS 020 Share QuestionEmailCopy link Comments (0)


