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

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?

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

panda_1 = Panda('Bao Bao', 47)
panda_1.eat()

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
MOD
Chris Freeman
Treehouse Moderator 68,457 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
seal-mask
STAFF
.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"......"