Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Basic Object-Oriented Python Welcome to OOP Adding to our Panda

What's wrong in my code, please?

I have set "Bao Bao" into the self.name. But, why is the system tell me it doesn't work?

panda.py
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.name = 'Bao Bao '
        self.is_hungry = False
        return f'{self.name} eats {self.food}'

4 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,778 Points

Hey diginoma, the eat() method is overriding the self.name attribute. Delete the assignment to self.name inside eat()

As it is now, it’s “Boa Boa eats”... all the time

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

I solve it

I put the code in the right position :-)

Thank you!

i'm having a similar problem... I get....

Traceback (most recent call last): File "", line 67, in test_results AssertionError: 'Bao Bao eats berries.' != 'Charles eats berries.'

  • Bao Bao eats berries.
  • Charles eats berries. : Make sure to use the attributes already in the class. When I create an instance with Charles as the panda's name and change the food attribute to berries, I don't get the right message.

whats the real problem here?

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.name = 'Bao Bao'
        self.is_hungry = False
        return f'{self.name} eats {self.food}.'
Chris Freeman
Chris Freeman
Treehouse Moderator 67,778 Points

Hey diginoma, the eat() method is overriding the self.name attribute. Delete the assignment to self.name inside eat()

As it is now, it’s “Boa Boa eats”... all the time

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

ohhhh!!! well when you put it that way now I get it! Thanks!!