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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Dominic Malloy](https://secure.gravatar.com/avatar/592e5f99db0766e024914de452623b2a?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Dominic Malloy
1,857 PointsMethod Challenge Task - Task 2
I'm not sure where I'm going wrong in this task. When I run this in VS Code it produces no errors. Thank you in advance.
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'
r = (f'{self.name} eats {self.food}.')
return r
1 Answer
![Asher Orr](https://uploads.teamtreehouse.com/production/profile-photos/11686423/micro_updated_headshot_2022.jpg)
Asher Orr
Python Development Techdegree Graduate 9,408 PointsHi Dominic!
Check out this error message:
Traceback (most recent call last):
File "", line 67, in test_results
AssertionError: 'Bao Bao eats berries.' != 'Charles eats berries.'
- Bao Bao eats berries.
+ Charles eats berries.
: Make sure to use the attributes already in the class. When I create an instance with Charles as the panda's name and change the food attribute to berries, I don't get the right message.
Since the challenge itself will run your code with 'Bao Bao' as the name attribute, you should delete this line:
self.name = 'Bao Bao'
When I ran your code after deleting that line, I still got an AssertionError (Regex didn't match).
I think it's because the task asks to return string, and not a variable.
Try returning a formatted f-String instead of the variable "r".
Let me know if that works!
![Dominic Malloy](https://secure.gravatar.com/avatar/592e5f99db0766e024914de452623b2a?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Dominic Malloy
1,857 PointsHi Asher, that worked!. Thank you for taking the time to help.
And thank you for your response Jeff, appreciate it.
Jeff Muday
Treehouse Moderator 28,718 PointsJeff Muday
Treehouse Moderator 28,718 PointsAsher Orr is correct, and you are correct too!
The Challenge automatic grader is using a unit test based on the output of a regular expression. The regular expression is expecting only a
return '${self.name} eats {self.food}.'
So it will mark as incorrect other valid ways of completing this exercise.
The moral of this story is to try a Challenge, if you can't complete it with a reasonable effort then ask the community and move ahead.