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 trialTyler Cortez
2,771 Pointsmethods
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
jb30
44,806 Pointsfood
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
2,771 PointsTyler Cortez
2,771 Pointsso 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 :)
jb30
44,806 Pointsjb30
44,806 PointsThe 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.