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

Jacinto Jacinto
seal-mask
.a{fill-rule:evenodd;}techdegree
Jacinto Jacinto
Python Web Development Techdegree Student 7,869 Points

Just need some clarification.

I just passed it by accident randomly typing in the answer, but it really doesn't make sense to me at all. Why does this work? I wish someone could give a good explanation why this works. I put the line number just incase if my code gets formatted the wrong way.

line1: @price.setter
line2: def price(self, price):
line3: self._price = price

______________and this doesn't:

line1: @price.setter line2: def price(self, price): line3: self._price = price / (1 + self.tax_rate)

for some reason we don't have to specify or modify anything for this example. We just use the parameter's unadulterated value and it magically gives us the price before tax. I mean I wouldn't make such a big deal out of it if it weren't for the fact that there is a huge issue of consistency here. In the video just before this we had to specify that self.diameter was equal to the radius MULTIPLIED by 2.

line1: @radius.setter line2: def radius(self, radius): line3: self.diameter = radius * 2.

with the logic of how we solved the quiz this should work perfectly:

line1: @radius.setter line2: def radius(self, radius): line3: self.diameter = radius

But it doesn't. Am I missing something here?

1 Answer

Steven Parker
Steven Parker
229,788 Points

The challenges and video examples are not the same.

They may seem similar, but they have different requirements so that (I'm sure intentionally) the video examples can't be directly used as answers to the challenge.

And diameter is always radius * 2 ... that's just math.

Greg Kaleka
Greg Kaleka
39,021 Points

Actually, they are the same. Jacinto Jacinto has it exactly right, and the challenge is coded incorrectly.

There's a _price attribute, which is the base price, and a price property, which is the net price after tax. The challenge asks you to create a setter for the price property, which again is net after tax. If you set the net price after tax, you need to adjust the _price attribute based on the tax rate.

Steven Parker
Steven Parker
229,788 Points

What I meant is that the challenges are usually not exactly the same as the follow-along video examples. At least not close enough that you can just copy and paste from the workspace to the challenge and pass.

And for this specific challenge, I interpreted a setter "that updates the _price attribute" as one that would update it directly, and the one I built on that interpretation passed the challenge. But it would certainly be more clear if the instructions mentioned "base price". And if that's really not what was intended, the code would need to be changed as you suggested plus it would be nice if the instructions mentioned "tax rate".

Either way, Jacinto Jacinto — it sounds like this might be worth reporting to Support. It may even get you the "special Exterminator badge".

Greg Kaleka
Greg Kaleka
39,021 Points

Yeah that's certainly true.

I do think there's some room for different interpretations on this challenge. I've actually contacted support myself. It should be clarified what's going on here. I think as it stands it's confusing at best.

some_product.price = 10
some_product.price # returns 11.20

That... can't be good practice. This is surprising behavior.