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 Adding to our Panda

Eduardo Larios
Eduardo Larios
86 Points

I cant get this challenge to work. I need help on explaining it

This code fails: class Panda: species = 'Ailuropoda melanoleuca' food = 'bamboo'

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

def eat(self):
    self.is_hungry = False
    return f'{self.name} eats {self.food}'
panda.py
class Panda:
    species = 'Ailuropoda melanoleuca'
    food = 'bamboo'

    def __init__(self, age, name='Bao Bao'):
        self.is_hungry = True
        self.name = name
        self.age = age

    def eat(self):
        self.is_hungry = False
        return f'{self.name} eats {self.food}'

1 Answer

Steven Parker
Steven Parker
242,031 Points

The instructions say "add two arguments to your class in the __init__ method called name and age". Remember that the order of arguments is important, and the instructions imply that "name" should be placed before "age".

But the code above shows that the argument "age" was added before "name", which would not work the same.

Also, the instructions don't ask you to include a default value for "name", but that extra step in itself won't cause an issue.