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 trialConnor Richardson
3,828 PointsMy 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)
panda_1.eat()
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsHey 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
return
is not a function call. There should be a space following it.
Post back if you need more help. Good luck!!!
Megan Amendola
Treehouse TeacherHi! 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"......"
Connor Richardson
3,828 PointsConnor Richardson
3,828 PointsError 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(.)