+ 1

dictionary of items and prices with discount added to total order

I have a dictionary of items and a dictionary of prices. If the total of items * prices is between $50 and $100, a 5% discount is applied. If the order is over $100, a 10$ discount is applies. Here is my guess, however I cannot get the discounts t work. (also the assertions have to stay) Thanks in advance! def calculate_price(price, order): count = 0 for i in order: if i in price: count = count + (price[i] * order[i]) return count while count > 0: if count <= 50: count = count print(count) elif 50 < count <= 100: count = count * 0.95 print(count) else: if count > 100: count = (count * 0.90) print(count) price = {'book': 10.0, 'magazine': 5.5, 'newspaper': 2.0} order1 = {'book': 10} order2 = {'book': 1, 'magazine': 3} order3 = {'magazine': 5, 'book': 10} assert(95 == calculate_price(price, order1)) assert(26.5 == calculate_price(price, order2)) assert(114.75 == calculate_price(price, order3)) print("Done")

28th Sep 2017, 8:02 AM
JUGHEAD
JUGHEAD - avatar
1 Antwort
+ 2
def calculate_price(price, order): count = 0 for i in order: if i in price: count += (price[i] * order[i]) if 50 <= count <= 100: count *= 0.95 elif count > 100: count *= 0.90 return count
28th Sep 2017, 9:26 AM
ChaoticDawg
ChaoticDawg - avatar