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

Valeshan Naidoo
Valeshan Naidoo
27,008 Points

setter challenge

I'm not sure if I fully understand the question being asked, but I get the error "cannot set @price property". I'm not too certain about class decorators yet so an explanation would be much appreciated. thanks in advance

product.py
class Product:
    _price = 0.0
    tax_rate = 0.12

    def __init__(self, base_price):
        self._price = base_price

    @property
    def price(self):
        return self._price + (self._price * self.tax_rate)

    @price.setter
    def price_setter(self, value):
        self._price = self._price + (self._price * self.tax_rate)
        return self._price
Jennifer Lithgow
Jennifer Lithgow
11,778 Points

I think you're using the decorator just fine! You did the exact same thing I did when I first tried this challenge, which was to mimic what the @property method was doing, but it turns out I was making it too complicated. All that is being asked for in this challenge is to make your @price.setter method set the "self.__price" to equal the "value" you passed. Short and sweet, with no need to add the calculated tax_rate or anything else. You don't even need to have a "return" at the end. Hope this helps!

2 Answers

Chris Christensen
Chris Christensen
9,281 Points

@JenniferLithgow I'm still not getting this one. Even with your suggestion, I try the following to no avail:

@price.setter
def price(self, _price):

I'm going to rewatch the video but hopefully, someone can shed some light on what I'm missing.

Chris Christensen
Chris Christensen
9,281 Points

I figured it out but it did require setting the self._price variable.

@price.setter
def price(self, change):
    self._price = change
Jennifer Lithgow
Jennifer Lithgow
11,778 Points

Exactly so! I'm sorry my comment didn't help get you all the way there, but I'm glad you were able to figure it out in the end! :)