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 trialMelissa Benton
Front End Web Development Techdegree Graduate 17,805 PointsHow 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?
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
Treehouse Moderator 38,297 PointsHi 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.
Melissa Benton
Front End Web Development Techdegree Graduate 17,805 PointsMelissa Benton
Front End Web Development Techdegree Graduate 17,805 PointsThank you Mark. Your answer was clear and helpful.