Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialOMAR JAMAL
4,577 PointsMake Sheep.noise() return the uppercased version of the instance's sound.
1st task
from animal import Animal
class Sheep(Animal): sound='growl'
2nd task
def sound(self): return self.sound()
player=Sheep() player.sound='Grrrr'
3rd task
def noise(self): return self.sound.upper()
I try this adding the noise method to make the self.sound to uppercase but it shows error....is there something missing or I have the wrong order of the code?
2 Answers
Kenneth Love
Treehouse Guest TeacherYour second task is a bit confused. It's a method that just returns itself because it calls itself (self.sound()
means call the sound
method that belongs to this instance).
You don't need to define a sound()
method, you need to set the sound
attribute. Basically exactly what you did for step 1.
In step 3, you need to rewrite noise()
just like you did. Your code is failing, though, because of how you defined sound
/sound()
in step 2.
MUZ140295 Malvern Dongeni
1,144 Pointshere is the what i did and its correct from animal import Animal class Sheep(Animal) pass
def init(self): self.sound='meeeeeeew' def noise(self) return self.sound.upper()