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 trialAndré Fosse
3,851 PointsHi to whomever will be my much needed helper! I'm having trouble figuring out how to return a string in the challenge.
I understand how to pass the arguments when calling the class but I don't know how to incorporate that into returning the string ' Bao Bao eats bamboo.
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
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, André Fosse! Looks like you're doing terrific so far. This return
really isn't going to be much different than any other return statement you've done so far But the key here is that we're using self.name
and self.food
inside the string:
return f"{self.name} eats {self.food}."
If the name of the Panda is "Bao Bao" and the food is "bamboo", then this returns the string "Bao Bao eats bamboo." But if the name of the panda was "Fluffy" and the food was (for some odd reason) "jelly beans", then it would return "Fluffy eats jelly beans."
Hope this helps!
André Fosse
3,851 PointsHi!! Thank you for your help Jennifer( hope its ok to use just your first name). I've had a long Christmas break and this is a LATE thank you for your help which sent me down the right track to clearing my code challenge blues!
Have a great day wherever you are and once again sorry for my tardy reply.