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

Tyler Cortez
Tyler Cortez
2,420 Points


little confused here how to add Bao Bao correcty into my string and if I'm properly calling the food. been stuck on this one for a few days trying to figure out where I'm wrong

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{food}')
Panda.__init__('Bao Bao',10)

1 Answer

food is a class variable. You can access its value within the Panda class using self.food. The challenge also requires a space after the word "eats" in the string that you return.

You don't need to create a Panda named "Bao Bao" to pass the challenge, but you could create a Panda by bao_bao = Panda('Bao Bao',10).

Tyler Cortez
Tyler Cortez
2,420 Points

so if I'm not creating a panda named Bao Bao how would I have the return use the name bao bao because if I do self.name = 'Bao Bao' inside the eat method it will not work? thank you :)

The example string shown in the challenge is to show the format of the string the method should return, of where the challenge expects spaces and punctuation. A Panda with a different name should use its own name when the eat method is called.