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

This code challenge test is wrong

This code challenge keeps failing for me even though it runs correctly in workspace. I have to instantiate the class in the workspace, but the instructions do not say to do that. The test is failing saying it is not finding the proper return string.

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

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 Points

Check the hint at the end of the answer ;-)

Sorry you are feeling frustrated. More than a few times I felt frustrated and angry at the challenge grader because it didn't appear to work.

You shouldn't have to instantiate the object because the unit test does that. Also note that the challenge grader is a stupid automaton, so it didn't accept my answer the first time because I omitted the '.' character at the end. ;-)

Hint: remove the parenthesis on the return value. That should remove one of your difficulties.

Ah, thank you for the hint, I have now gotten past that challenge. It would be nice if the grader actually passed based on what was returned, not just a regex matching a text pattern.

Beyond that I still think this question should be reworded. It says the string would return "Bao Bao eats bamboo" but the code does not set name="Bao Bao" anywhere, so that was another very confusing part of the challenge. Maybe add an additional instruction to instantiate the class setting name="Bao Bao".