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

Andy McDonald
Andy McDonald
2,767 Points

Dont know how to make an attribute to an __init__ method while only passing the self argument.

Problem asks: Create a class called Panda. Inside your class, create two class attributes. One called species set to ‘Ailuropoda melanoleuca’ and another called food set to ‘bamboo’. The best I can do: class Panda: species = 'Ailuropoda melanoleuca' food = 'bamboo'

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

fat_panda = Panda()

Error says that 1 != 2. Can only pass the self argument. Pretty sure I have not been taught to do that yet...

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

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

fat_panda = Panda()

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 65,196 Points

You are so close. The task does not ask for any __init___ parameters. It wants you to hard code the value to True So,

self.is_hungry = True

Now the extra parameter can be removed.

As for passing an argument to __init__, your syntax would be correct.

Post back if you need more help. Good luck!!!