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

Python Basic Object-Oriented Python Welcome to OOP Adding to our Panda

OOP I don't know why it's wrong

Create a method called eat. It should only take self as an argument. Inside of the method, set the is_hungry attribute to False, since the Panda will no longer be hungry when it eats. Also, return a string that says 'Bao Bao eats bamboo.' where 'Bao Bao' is the name attribute and 'bamboo' is the food attribute.

panda.py
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 {Panda.food}.')

2 Answers

I try self.food, but it still does not work. The same error appears: Bummer: AssertionError: Regex didn't match: 'return\sf?\\'?\"?\{[self.name]\}\seats\s\{[self.food]\}.\\'?\"?[.format]\(?[name\s=\s][self.name,]\s?[food\s=\s][self.food]*\)?' not found in "class Panda:\n species = 'Ailuropoda melanoleuca'\n food = 'bamboo'\n\n def init(self, name, age):\n self.is_hungry = True\n self.name = name\n self.age = age\n \n def eat(self):\n self.is_hungry = False\n return (f'{self.name} eats {self.food}.')" : Use string formatting and backets ({}) to add the name and food attributes to your string. Make sure the message has the correct spelling and a period(.)

Mark Sebeck
Mark Sebeck
Treehouse Moderator 37,905 Points

Sorry about that Marcus. You also need to delete the parenthesis on the return for it to pass.

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 37,905 Points

In your return instead of Panda.food it should be self.food. Self represents the instance of Panda that you are using.

Keep at it Marcus!