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 trialMaziko Mphepo
2,915 PointsStuck on task 2 of 3, creating classes in python
When I run my code I get this message "When I call the eat method, I don't get the correct message. Make sure to use the name attribute that is passed in to the instance" the code is supposed to return the text "Bao Bao eats Bamboo". Any help on how I can go about this
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
self.name = 'Bao Bao'
return (f"{self.name} eats {self.food}")
2 Answers
Jeff Muday
Treehouse Moderator 28,720 PointsYou're pretty close to the correct answer.
Just delete the line where you set the name and add a period at the end of the last string return. You should also delete the parenthesis around the return statement -- this is a personal preference. The Challenge grader is unfortunately picky and you have to get it 100% correct!
The Challenge grader does the rest. Good luck with your Python journey!!
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 {self.food}."
Maziko Mphepo
2,915 PointsThank you so much Jeff Muday