Question: class Enemy ( ) : def _ _ init _ _ ( self , name, life ) : self.name = name.title ( ) self.life =

class Enemy():
def __init__(self, name, life):
self.name = name.title()
self.life = float(life)
def reduce_life(self, hit):
if hit >0:
self.life -= hit
def __repr__(self):
if self.life >0:
return f"{self.name} has {self.life} HP left."
else:
return f"{self.name} is knocked out."
class Weapon():
def __init__(self, name, hit):
self.name = name.title()
self.hit = hit
self.use_count =0
def display_hit(self):
print(f"{self.name} removes {self.hit} HP from the enemy.")
def display_use_count(self):
if self.use_count ==1:
print(f"{self.name} is used once.")
else:
print(f"{self.name} is used {self.use_count} times.")
########
# DO NOT CHANGE ANYTHING ABOVE!!!
# YOU ARE SUPPOSED TO DEFINE THE METHDOS IN Sword() CLASS!!!
########
class Sword(Weapon):
def __init__(self,name,hit=100):
super().__init__(name,hit)
self.name = name
self.hit = hit
def enchant(self):
enchanment_status =bool( self.enchant())
if 0:
return f"{self.name} is enchanted, removes {self.hit} HP at use."
else 1:
return f"{self.name} is not enchanted, removes {self.hit} HP at use."
while True:
self.enchant()== hit*1.5
def use(self):
if self.use = self.life - self.hit:
def __repr__(self):
self.name= name
self.enchanment_status = enchanment_status
self.hit = hit
########
# DO NOT CHANGE ANYTHING BELOW!!!
# THE TEST CODE IS SUPPOSED TO WORK IN A SIMILAR FASHION AS DEPICTED ON THE
# EXAM SHEET !!!
########
orc = Enemy("ausk",420)
print(orc)
s1= Sword("sting")
s1.display_use_count()
print(s1)
s2= Sword("ashbite",80)
s2.display_use_count()
print(s2)
s1.use(orc)
print(orc)
print(s1)
s2.enchant()
print(s2)
s2.enchant()
print(s2)
s2.use(orc)
print(orc)
print(s2)
s2.use(orc)
print(orc)
s1.enchant()
print(s1)
s1.use(orc)
print(orc)
print(s1)
s1.display_use_count()
s2.display_use_count()

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!