Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python (retired) Inheritance Override Inherited Methods

Make 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
Kenneth Love
Treehouse Guest Teacher

Your 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.

here 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()