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

Akshaan Mazumdar
Akshaan Mazumdar
3,127 Points

Unable to get the name right

Not sure how to get ' Bao Bao' to print in this challenge

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("Bao Bao",14)

1 Answer

Brandon White
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Treehouse Moderator

Hi Akshaan,

You’re actually printing the ‘Bao Bao’ portion just fine in this challenge. The bug you’re running into is that you’re not printing the bamboo portion of the statement, and your string is missing a period at the end. Both of those minor issues are keeping your return string from matching the string requested in the challenge instructions.

So to fix the food part, you just need to write self.food instead of food. food does not exist as a variable by itself. So you have to call it on the instance of the Panda object.

Make those changes (don’t forget the period at the end of your f string), and you’ll make your way to challenge number 3.

SN: Another way you should be able to print the bamboo portion of 'Bao Bao eats bamboo.' is by not calling self.food and instead calling Panda.food. You can do this because food is a class attribute, which means it's already present on the class and isn't created on instantiation. So just like typing print(Panda.species) into the same script file should give you an output of: Ailuropoda melanoleuca, calling ... eats {Panda.food}." should get you ... eats bamboo., but because of the way Treehouse is using Regex to test this challenge, that's not an option here. But I wanted to let you know that it could be an option in your own personal projects.