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

Leila Hardy
Leila Hardy
5,601 Points

Help! I am working on the inheritance badge in Python and I am really stuck on the last code challenge.

Here is my code:

import animal
class Sheep(Animal): 

I know that it's wrong, but I'm not sure why. Any pointers?

You imported animal module not the Animal class. You should use:

from animal import Animal
Leila Hardy
Leila Hardy
5,601 Points

I am still getting this error:

Bummer! SyntaxError: class Sheep(Animal):

My code now is this:

from animal import Animal

class Sheep(Animal):

Thank you for your help!

3 Answers

You also need to add 'pass' in third line, as suggested in the code challenge. Or you can define a class variable. You need a line of code there.

Leila Hardy
Leila Hardy
5,601 Points

Yay! Thank you for your help! I have gotten through the first and second tasks, but have one last question about the third task. The question is: "Animal.noise() returns self.sound.lower(). Make Sheep.noise() return the uppercased version of the instance's sound" Here is my code:

from animal import Animal class Sheep(Animal): pass sound = 'baa' def Sheep.noise(): return sound.upper()

I am getting the error: 'Oops! It looks like Task 1 is no longer passing.' What does this mean, and what do I need to fix?

Leila Hardy
Leila Hardy
5,601 Points

sorry, Markdown is not working at all for me

You need to remove 'pass' once you write actual code. It is supposed to be a place holder till you write actual code. Also the sound is instance variable, so, it should be: return self.sound.upper() Also you cant write Sheep.noise, the name of method should be noise (hence def noise()) Not sure why previous task is failing.

Leila Hardy
Leila Hardy
5,601 Points

Update: I figured out the code challenge; here is my code:

from animal import Animal
class Sheep(Animal):
  sound = 'baa'

  def noise(self):
    return self.sound.upper()

Cool. Hope I nudged you towards right direction. Did not want to post solution. :)