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

Melissa Benton
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Melissa Benton
Front End Web Development Techdegree Graduate 17,230 Points

How do I change the panda name?

I'm struggling to write the code to pass the argument 'Bao Bao' to the name parameter in the instance attribute so it can be used in the return f-string. I've tried numerous ways and the logic still doesn't work. How do I pass "Bao Bao" to the name parameter?

panda.py
class Panda:
    species = 'Ailuropoda melanoleuca'
    food = 'bamboo'

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

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

1 Answer

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 37,341 Points

Hi Melissa Benton. You don't actually need to pass 'Bao Bao' to the name. That would be passed when the class is initialized. However, don't forget to include "self." in front of name and food in your string literal.

return f'{self.name} eats {self.food}.'

This question is confusing because they used Bao Bao as an example of a name. But think of it this way, anything in the init you would want to set for each Panda you create. Each one would have their own name and age. Things like species and food are set in the class because they don't change. Hope this helps and post back to the forum if you are still stuck.