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

Sapir Lapid
Sapir Lapid
2,744 Points

The price.setter challenge has a wrong answer.

If the property price includes tax, then the setter should expect a price with tax too.

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

2 Answers

Sapir Lapid
Sapir Lapid
2,744 Points

Right, that's the instruction, but it still teaches a wrong design choice.

They could chose to implement another property named "tax" and then return price without the tax. They could implement a property named "final_price" to include tax.

These are just few examples. But using the same exact property "price" to mean 2 different things in setter vs getter is just wrong.

Steven Parker
Steven Parker
231,275 Points

This is actually good practice for anyone who might eventually be developing in a corporate environment. You'll often be instructed to implement design choices you might not agree with! :speak_no_evil:

Steven Parker
Steven Parker
231,275 Points

That was my first thought also; but then I realized it's probably more typical for a merchant to establish prices before tax, even though they might want to display the total with tax to the customer.

But the design choice isn't really the issue, for the challenge you only need to implement what the instructions literally asked for (which is a direct setter "that updates the _price attribute").