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 trialAriadna Rodriguez
6,281 PointsCreate 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
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
Treehouse TeacherHi 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
Hope this helps!
Megan L
2,905 Pointsclass 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
2,905 PointsThis 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.
Learn QA
7,207 Pointsclass 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()
Ariadna Rodriguez
6,281 PointsAriadna Rodriguez
6,281 Pointsthat worked! thanks for your help.