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 Basic Object-Oriented Python Welcome to OOP Creating a Panda Class

error: Your init method should be declared with `def` and take only self as an argument.

I tried a couple of different codes and they all fail with this error message

def init(self):

should be right... right? or do i have to do this

def init(self, is_hungry=True):

panda.py
# insert your code here
class Panda:
    species = "Ailuropoda melanoleuca"
    food = "bamboo"
    is_hungry = True

def __init__ (self):

    Panda.is_hungry=True

1 Answer

Hi Jan!

A couple of issues:

1) the init method should be a class method, so it should be indented (4 spaces) to line up with the species and food class attributes

2) is_hungry should be set only inside the init method

3) eliminate the space between init and (self):

This passes:

# insert your code here
class Panda:
    species = "Ailuropoda melanoleuca" # indented 4 spaces
    food = "bamboo" # indented 4 spaces

    def __init__(self): # indented 4 spaces
        self.is_hungry = True # indented 8 spaces

Make sure to always indent in multiples of 4 spaces (4/8/12/16/20/etc. - don't use tabs)

I hope that helps.

Stay safe and happy coding!