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

I can't figure out how to call the eat method

Create another method called check_if_hungry that also only takes self. Inside of the method, if the is_hungry attribute is True, then call the eat method.

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 {self.food}.'
    def check_if_hungry(self):
        if is_hungry = True:
            return eat



panda_one = Panda('Bao Bao', 10)
panda_one.eat()

4 Answers

Your new error, the SyntaxError, is because = is an assignment operator! In order to compare in an if statement, it has to be == which is a comparison operator. I hope this helps!

It says I have a syntax error now if is_hungry = True: ^ SyntaxError: invalid syntax

def check_if_hungry(self): if is_hungry == True: return eat(self)

panda1 = Panda("Boa Boa", 10)
panda1.eat()

I seem to keep getting the: : You should be checking if the is_hungry attribute is true. Make sure to use self to call the attribute.error

def check_if_hungry(self):

    if is_hungry == True:

        return eat(self)

panda1 = Panda("Boa Boa", 10)

panda1.eat()

whats wrong with my code: AssertionError: Regex didn't match: 'if\sself.is_hungry\s?=?=?\s?[True]*:' not found in 'class Panda:\n species = \'Ailuropoda melanoleuca\'\n food = \'bamboo\'\n\n def init(self):\n self.is_hungry = True\n def init(self, name, age):\n self.name = name\n self.age = age\n def eat(self):\n self.is_hungry = False\n return f"{self.name} eats {self.food}."\n def check_if_hungry(self):\n if is_hungry == True:\n return eat(self)\n\n \npanda1 = Panda("Boa Boa", 10) \npanda1.eat()' : You should be checking if the is_hungry attribute is true. Make sure to use self to call the attribute.