On Sunday, February 2, 2014 11:38:57 AM UTC-5, MRAB wrote: > On 2014-02-02 16:11, David Hutto wrote: > > > price_per_book = 24.95 > > > discount = .40 > > > quantity = 60 > > > > > The original problem says: > > > > Suppose the cover price of a book is $24.95, but bookstores get a 40% > > discount. Shipping costs $3 for the first copy and 75 cents for each > > additional copy. What is the total wholesale cost for 60 copies? > > > > > Here: > > > discounted_price = (1-discount) * price_per_book > > > > > > The discounted price should be price_per_book - discount > > > > > No, the discount of 0.40 is 40%, not 40 cents. > > > > > shipping = 3.0 + (60 - 1) * .75 > > > shipping should be, I think, should be 3.0 + (quantity * .75) > > > > > No, the shipping is 75 cents starting from the second copy. > > > > > total_price = 60 * discounted_price + shipping > > > replace 60 with quantity (quantity * discounted_price) + shipping > > > > > > print total_price, 'Total price' > > > > > > total_price gives: > > > 945.45 Total price > > > and just 24.55(price per book - discount is ) * quantity is $1473 without > > the shipping, so the total is way off already: > > > > > > > > > I think the following is what you're looking for: > > > > > > price_per_book = 24.95 > > > discount = .40 > > > quantity = 60 > > > discounted_price = price_per_book-discount > > > shipping = 3.0 + (quantity*.75) > > > total_price = (quantity * discounted_price) + shipping > > > print 'Total price: $%d' % (total_price) > > > Total price: $1521 > > >
Revised: price_per_book = 24.95 percent_discount = .40 discounted_price = price_per_book - (price_per_book * percent_discount) quantity = 60 shipping = 3.0 + ((quantity - 1)*.75) total_price = (quantity * discounted_price) + shipping print 'Total price: $%d' % (total_price) -- https://mail.python.org/mailman/listinfo/python-list