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

Stuck again.

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'
    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 f'{self.name} eats {self.food}.'

2 Answers

boi
boi
14,242 Points

You're word away from completing the challenge. Read the instructions carefully " if the is_hungry attribute is True, then CALL THE EAT METHOD".

The challenge requires you to Call the eat() method.

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 f'{self.name} eats {self.food}.' 👈#Here.

Thank you much again!!

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()

i put in exactly how both codes look ad keep getting:

AssertionError: 'self.eat()' 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 self.is_hungry == True:\n return f\'{self.name} eats {self.food}.\'' : Inside of the if statement, call the eat method using self.

Hey Evelyn Meza, I apologize for such late response time, but I'll just forward you to this community discussion covering the same section. You might find your answer and a solid understanding there. If you're still having trouble after that, then I'll see what I can do. Take it easy and keep up the great work!

Community Discussion:

Your Willy Wonka golden ticket is HERE