Python Basic Object-Oriented Python Welcome to OOP Creating a Panda Class

Tucker Fischer
Tucker Fischer
8,629 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.

Michael Jones
seal-mask
.a{fill-rule:evenodd;}techdegree
Michael Jones
Python Development Techdegree Student 30,570 Points

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 Henri Tokwaulu
Paul Henri Tokwaulu
13,663 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