Bummer! You must be logged in to access this page.

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 Object-Oriented Python Advanced Objects Dream Car

Trinidad Ramirez
Trinidad Ramirez
5,849 Points

Code works in workspaces. Why am I getting this error in the challenge task?

When I run this code in workspaces, it compiles fine and I get the desired output. When I run the same code in the challenge task, I get the following error:

FAIL: test_function_code (main.TestFunctionDefinitionCode)

Traceback (most recent call last): File "", line 43, in test_function_code AssertionError: Regex didn't match: '(\{self.make\})\s(\{self.model\})' not found in 'class DreamCar:\n\tdef init(self, make, model):\n\t\tself.make = make\n\t\tself.model = model\n\t\t\n\tdef str(self):\n\t\treturn "My dream car is a {} {}.".format(self.make, self.model)' : You'll need to use self when using the attributes make and model.

Why is this?

dream_car.py
class DreamCar:
    def __init__(self, make, model):
        self.make = make
        self.model = model

    def __str__(self):
        return "My dream car is a {} {}.".format(self.make, self.model)

1 Answer

I had the same problem, it is something in the code interrupter that doesn't let it work. Instead you have to use an 'f-string'.

    def __str__(self):
        return f"My dream car is a {self.make} {self.model}."
Trinidad Ramirez
Trinidad Ramirez
5,849 Points

That did the trick! Thanks Michael