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

Food is not defined

I've been working on this for a bit not really sure what to do, appreciate any help.

panda.py
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, name, food):

        is_hungry = False
        print(f'{name} eats {food}.')
Panda.eat('Bao Bao', food)

1 Answer

Eric Ryan
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Eric Ryan
Python Development Techdegree Graduate 26,123 Points

There should be another empty line between the init and eat methods and the empty line after the first line of the eat method is unnecessary. The food attribute is defined in the class, so the eat method doesn't need any other argument besides 'self'. The name is set when the instance is initialized, so again it doesn't need to be an argument in the eat method. Then you should also be returning a string, not calling the print function.

So try removing 'name' and 'food' as arguments in the eat method, and then rather than printing the f-string just return it. Calling Panda.eat() isn't necessary to pass that part of the challenge.

Converted comment to answer - Dane Parchment (Moderator)

Thanks for the help, I was able to complete it.