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

Create another method called check_if_hungry that also only takes self. Inside of the method, if the is_hungry attribute

I don't understand why I am getting a syntax error

panda.py
class Panda:
    species = 'Ailuropoda melanoleuca'
    food = 'bamboo'

    def __init__(self, name, age):
        self.name = name
        self.age = age
        self.is_hungry = True

    def eat(self):
        self.is_hungry = False
        return "{} eats {}." .format(self.name, self.food)

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

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Ariadna Rodriguez! There are a couple of things going on here. First, you're meaning to ask if is_hungry is True with a double equals as opposed to a single equals. Remember that a single equal is an assignment. You're looking for if self.is_hungry == True:.

Secondly, The final line with self.eat() should be indented inside the if statement. You need to move that line over to the right :smiley:

Hope this helps! :sparkles:

that worked! thanks for your help.

Megan L
Megan L
2,905 Points
class Panda:
    species = 'Ailuropoda melanoleuca'
    food = 'bamboo'
    name = 'Bao Bao'

    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 self.is_hungry:
            return self.eat()
Megan L
Megan L
2,905 Points

This question bothered me alot since it very picky on syntax. This is the full answer to complete challenge 1-3 hopes it help someone else.

class Panda: species = 'Ailuropoda melanoleuca' food = 'bamboo' name = 'Bao Bao'

def __init__(self, name, age):
    self.is_hungry = True
    self.name = name
    self.age = age

def eat(self):
        self.is_hungry = False
        return "{} eats {}.".format(self.name, self.food)

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