Help with some python homework...
rhodri at wildebst.org.uk
Sun Feb 2 18:15:05 CET 2014
On Sat, 01 Feb 2014 05:18:34 -0000, Scott W Dunning <swdunning at cox.net>
> Any chance you guys could help with another question I have? Below is a
> code to a different problem. The only thing I don’t understand is why
> when calculating the 'discounted price’ you have to subtract 1? Thanks
> again guys!
> price_per_book = 24.95
> discount = .40
> quantity = 60
> discounted_price = (1-discount) * price_per_book
> shipping = 3.0 + (60 - 1) * .75
> total_price = 60 * discounted_price + shipping
> print total_price, 'Total price'
The thing that is confusing you is that "discounted_price" is conflating
several steps into one. Think of it like this:
* "discount" is the discount rate; in this case meaning that a book costs
40% less than its list price ("price_per_book").
* In other words, the book costs "discount * price_per_book" less than
its list price.
* So the book costs "price_per_book - (discount * price_per_book)" after
applying the discount.
* refactoring, that's "(1 - discount) * price_per_book." Ta da!
Rhodri James *-* Wildebeest Herder to the Masses
More information about the Python-list