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

Tucker Fischer
Tucker Fischer
10,517 Points

create an instance attribute called is_hungry and set it equal to True.

Add an init method to your class. It should only take the self argument. Inisde the method, create an instance attribute called is_hungry and set it equal to True.

Here is my code. Where do you think I went wrong?

class Panda: species = 'Ailuropoda melanoleuca' food = 'bamboo' hungry = True

def __init__(self, hungry):
    self.hungry = hungry

is_hungry = Panda('True')

panda.py
class Panda:
    species = 'Ailuropoda melanoleuca'
    food = 'bamboo'
    hungry = True

    def __init__(self, hungry):
        self.hungry = hungry


is_hungry = Panda('True')

1 Answer

Megan Amendola
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher
class Panda:
    species = 'Ailuropoda melanoleuca'
    food = 'bamboo'

    def __init__(self):
        self.is_hungry = True

You should just be creating an instance variable set to True like so.

This code: is_hungry = Panda('True') creates a variable called is_hungry that holds an instance of the Panda class where you have set the value of the is_hungry instance attribute to 'True' which is a string not a boolean.

Afternoon,

Sorry, but I'm a little confused to why you added a class attribute to the class. The second question said - "Add an init method to your class. It should only take the self argument. Inisde the method, create an instance attribute called is_hungry and set it equal to True."

So isn't that asking us to to create an init method within the class and create a default value within? So shouldn't it look like below?

    def __init__(self, is_hungry = True):
        self.is_hungry = is_hungry

Hope you can help. :)

Paul H T
Paul H T
19,742 Points

def init(self, is_hungry = True):

       self.is_hungry = is_hungry 

This should have been the answer... You guys need to fix it

-> or you need to have a video response to explain your logic which is completely different from the video lesson about the instance attribute