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 trialTapiwanashe Jandura
2,677 PointsI really don't know where I'm getting it wrong here
How am I supposed to call eat()
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 self.is_hungry = True:
return self.eat()
1 Answer
Magnus Martin
44,123 PointsHi,
first you should fix error in line 15 where you are assigning a value instead of comparing:
if self.is_hungry == True:
To let your panda eat ou should create a new panda first:
panda1 = Panda("flippy", 12) # new panda called "flippy" with the age of 12
Then you can let him eat:
panda1.eat()
To check if eating method works, you can print is_hungry state before and after eating:
print(panda1.is_hungry)
panda1.eat()
print(panda1.is_hungry)
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 self.is_hungry == True:
return self.eat()
panda1 = Panda("flippy", 12)
print(panda1.is_hungry)
panda1.eat()
print(panda1.is_hungry)