Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Basic Object-Oriented Python Welcome to OOP Adding to our Panda

My code appears to output the desired result, yet it is not being accepted.

As stated when tested in workspace this code outputs the desired result. Yet it is not being accepted. What am I doing wrong?

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}.")

panda_1 = Panda('Bao Bao', 47)

Error message received

AssertionError: Regex didn't match: 'return\s\(?f?\\'?\"?\{[self.name]\}\seats\s\{[self.food]\}.\\'?\"?[.format]\(?[name\s=\s][self.name,]\s?[food\s=\s][self.food]*\)?\)?' not found in "class Panda:\n species = 'Ailuropoda melanoleuca'\n food = 'bamboo'\n\n def init(self,name,age):\n self.is_hungry = True\n self.name = name\n self.age = age\n \n def eat(self):\n self.is_hungry = False\n return('{} eats {}.' .format(self.name, self.food))\n \npanda_1 = Panda('Bao Bao', 'age')\npanda_1.eat()" : Use string formatting and backets ({}) to add the name and food attributes to your string. Make sure the message has the correct spelling and a period(.)

2 Answers

Chris Freeman
Chris Freeman
Treehouse Moderator 67,464 Points

Hey Connor Richardson, looking closely at the unmatched regex:

AssertionError: Regex didn't match: 'return\s\(?f?...

It is looking for:

  • “return” the return keyword
  • “\s” a space (required)
  • “(?” an optional open paren
  • “f?” an option f for an f-string

:point_right: return is not a function call. There should be a space following it.

Post back if you need more help. Good luck!!!

Megan Amendola
.a{fill-rule:evenodd;}techdegree seal-36
Megan Amendola
Treehouse Teacher

Hi! return is a keyword, not a function call. If you include the () you can end up turning your return into a tuple on accident (if you have a comma in there). Instead, you just need to use the keyword and then a space to use it like this: return f"......"