Below is the test cases and after that is my code
What I need is to correct is my error within self.teach. In the test cases below, my code states " meow meow says meowpurr" when the correct one is " meow meow says meow and purr". The other test cases are correct.
#test cases
meow_meow = Tamagotchi("meow meow")
meow_meow.teach("meow")
meow_meow.play()
>>>>"meow meow says meow"
meow_meow.teach("purr")
meow_meow.teach("meow")
meow_meow.play()
>>>>'meow meow says meow and purr' #My own code state " meow meow says meowpurr"
Using my code:
class Tamagotchi(object):
def __init__(self, name):
self.name = name
self.words = str(self.name) + " says "
#check alive, dead within all the methods
self.alive = True
#trouble portion
def teach(self, *words):
if self.alive == False:
self.words = self.name + " is pining for the fjords"
return self.words
else:
listing = []
for word in words:
listing.append(str(word))
B = " and ".join(listing)
self.words += B
def play(self):
return self.words
def kill(self):
if self.alive == True:
self.words = self.name + " is pining for the fjords"
self.alive = False
return self.name + " killed"
else:
return self.name + " is pining for the fjords"
Thanks