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

How exactly does this want me to do this?

I have tried everything I know how to do and I can't figure out why I keep getting an AssertionError.

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):
       print(f'{self.name} eats {food}')
       if self.is_hungry == True:
            return False

1 Answer

boi
boi
14,242 Points

You have two errors. Let us analyze.

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):
       print(f'{self.name} eats {food}')👈# Need to use return not print. Also "food" is a class attribute, you need to call it as                                         
                                          #a class attribute. I'm pretty sure you know how to call class attributes.
       if self.is_hungry == True: 👈# You need to assign self.is_hungry to False, NOT give in an "if" condition and return it.             
            return False

Make these changes, if the problem persists. Let me know.

Wish I could double upvote this! I was so stuck on this for some reason. Thanks a ton!