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 Proper Properties

Is This Code Challenge Broken?

I'm fairly certain my code is correct but for some reason it won't go through. Is there some error in my code that I can't see or is there an issue with the code challenge?

rectangle.py
class Rectangle:
    def __init__(self, width, length, area):
        self.width = width
        self.length = length
        self.area = area

    @property
    def area(self):
        return self.width * self.length

    @property
    def perimeter(self):
        return (self.width + self.length) * 2

1 Answer

Steven Parker
Steven Parker
229,732 Points

This assignment not only is unnecessary, it overrides your computed property with a static value:

        self.area = area

I removed that assignment and it still doesn't work?

I found another solution on the forums

class Rectangle:
    def __init__(self, w, l):
        self.w = w
        self.l = l
    @property
    def area(self):
        return self.w*self.l

For some reason this code works and all it does is replace width with w and length with l. When I tried this it worked however my first attempt still didn't work even after removing the "self.area = area" declaration.

Steven Parker
Steven Parker
229,732 Points

The original solution had one other error, an "area" paramter had been added to the "__init__" method, which was not part of the instructions and prevented the validator from being able to create a class instance.