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 trialMohammad Aslam
6,053 PointsSetting the base price with property setter
Hi there,
I think I have the right answer. Why am I getting an error?
Appreciate your help with this.
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 = price / (1 + self.tax_rate)
2 Answers
Steven Parker
231,261 PointsFor this exercise, they're just looking for a function that updates the price directly. Your setter function won't need to perform any math operations, just a direct assignment.
Mohammad Aslam
6,053 PointsOk Thanks
Mohammad Aslam
6,053 PointsMohammad Aslam
6,053 PointsThanks, but I don't understand why. The two prices are different.
Steven Parker
231,261 PointsSteven Parker
231,261 PointsI don't think the challenge explains how they are used in detail. Apparently the setting is being done with the base price, and the display is showing the retail (plus tax) price.