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

Whatever I do I can't get it to work without it saying make sure you're using the correct spelling and a period

Can't get past this step, it keeps saying my spelling is wrong, but it could be my code too. Can't figure out how to resolve this problem

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):
        self.is_hungry = False
        self.name = 'Bao Bao'
        return(f'{self.name} eats {self.bamboo}.')

1 Answer

boi
boi
14,242 Points

You have one Attribute Error, one Wrong Assignment Error, and one Not an Error. Let us analyze these three errors.

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

        self.name = 'Bao Bao'  👈#Wrong Assignment Error

        return(f'{self.name} eats {self.bamboo}.') 👈#Attribute Error and Not an Error

Wrong Assignment Error:

Why did you set self.name to "Bao Bao"? The __init__ method has already handled the self.name argument. You don't need to set it to a specific name, what if the user wants to set it to some other name? So yea, remove it.

Attribute Error:

The word "bamboo" is a string literal value, which is stored to the food attribute of the class Panda. So calling self.bamboo will throw you an attribute error, because "bamboo" is not an attribute of the class, rather its the value of the food attribute. I'm pretty sure you know how to call an attribute.

Not an Error:

This is a Bull**it error, fix it by adding a space after the return like this:

return (f'{self.name} eats {self.bamboo}.')👈#Added space after return.

If you need help, let me know.