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 trial

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