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 trialDima Mykhaylov
19,379 PointsIs 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?
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
231,269 PointsThis assignment not only is unnecessary, it overrides your computed property with a static value:
self.area = area
Dima Mykhaylov
19,379 PointsDima Mykhaylov
19,379 PointsI removed that assignment and it still doesn't work?
Dima Mykhaylov
19,379 PointsDima Mykhaylov
19,379 PointsI found another solution on the forums
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
231,269 PointsSteven Parker
231,269 PointsThe 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.