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

Add a new property to the Rectangle class named area. It should calculate and return the area of the Rectangle instance.

Hello Cant seem to get this one to work, appreciate the help.

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

2 Answers

AJ Salmon
AJ Salmon
5,675 Points

For sure. You're really close!

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

That's it! I'm not sure how you had yours indented, but you just need to make sure that your return is contained in the area method. For the next task, it's the exact same idea; start with a @property decorator, then write the perimeter method that it asks for. In these cases, the@property decorator makes it so you call the area(self) method like it is just a normal property, when in reality it is a method that contains something to be run when the property is set. Hope this helps!

AJ Salmon
AJ Salmon
5,675 Points

You've got the right idea! Everything is correct so far. You just need to finish writing what the property is, so return self.width * self.length in the area property. Let me know if you need any more clarification!

Hey AJ! thanks for your help. But I tried inputting the code and it is still coming up incorrect.

I would appreciate it if you could give me the answer written out so I can work backwards and figure it out. This challenge has me held up pretty bad.

Heres the code:

class Rectangle: def init(self, width, length): self.width = width self.length = length @property def area(self): return self.width * self.length

Thanks!