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

Akshaan Mazumdar
Akshaan Mazumdar
3,787 Points

Unable to get the name right

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

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

Panda("Bao Bao",14)

1 Answer

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.