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

Bawar Noori
Bawar Noori
2,580 Points

My setter is not working correctly. With that said, when I personally test the code, it is functional and correct.

When I remove the rounding function from my code, I am still told the output is not correct. When I test the code, the value of the set value (price) is changed by a small decimal.

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(self, price):
        self._price = round(price / (1 + self.tax_rate), 2)

1 Answer

Eric M
Eric M
11,545 Points

Your code is fine, this challenge is not clear in its requirements. The bad news is this is also true of many professional projects :P

Anyway, the challenge just wants you to round the price in the setter, no need to include the tax rate division.

i.e. Change: self._price = round(price / (1 + self.tax_rate), 2) to: self._price = round(price, 2)