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

Spinning my wheels and exhausting my resources. Would like some help please.

Create a method called eat. It should only take self as an argument. Inside of the method, set the is_hungry attribute to False, since the Panda will no longer be hungry when it eats. Also, return a string that says 'Bao Bao eats bamboo.' where 'Bao Bao' is the name attribute and 'bamboo' is the food attribute.

This is currently where I'm at in my toil

panda.py
class Panda:
    species = 'Ailuropoda melanoleuca'
    food = 'bamboo'
    name = 'Bao Bao'

    def __init__(self, name, age):
        self.is_hungry = False
        self.name = name
        self.age = age

    def eat(self):
        return Bao Bao eats bamboo

1 Answer

boi
boi
14,242 Points

The teacher wants to play a little gotcha game with this challenge, but in a good way, to practice your brain. Coming to the challenge, the challenge states "return a string that says 'Bao Bao eats bamboo.' where 'Bao Bao' is the name attribute and 'bamboo' is the food attribute.". I want you to read this sentence more carefully, three times.

Let's take a look at your code.

class Panda:
    species = 'Ailuropoda melanoleuca'
    food = 'bamboo'
    name = 'Bao Bao'

    def __init__(self, name, age):
        self.is_hungry = FalseπŸ‘ˆ# This should be TRUE not FALSE
        self.name = name
        self.age = age

    def eat(self):
        return Bao Bao eats bamboo  πŸ‘ˆ# Completely wrong syntax or statement.

Lemme ask you a question, what is Bao Bao eats bamboo in the context of your code? You wrote it as a variable, does Bao Bao eats bamboo hold any value here?. What would've made sense if you made "Bao Bao eats bamboo" a string literal, BUT even that would've been wrong according to the challenge.

The challenge wants you to return;

"name attribute eats food attribute"

If you are still confused or stuck, just msg me here.

β€œThank you boi” (in Kratos’ voice)