Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. base_price = 800
  2. discounts = [ 0, .05, .10, .20, .25]
  3.  
  4. def calculate_discounts(book_counts):
  5.     book_count = 0
  6.     for k, v in book_counts.items():
  7.         if v > 0:
  8.             book_counts[k] -= 1
  9.             book_count += 1
  10.     if book_count == 0:
  11.         return 0
  12.     print(f"Books: {book_count} * Base Price: {base_price} * Discount: {discounts[book_count-1]}")
  13.     return book_count * base_price * (1-discounts[book_count-1]) + calculate_discounts(book_counts)
  14.                
  15.  
  16. def total(basket):
  17.     book_counts = {}
  18.     for i in basket:
  19.         book_counts[i] = book_counts.get(i, 0) + 1
  20.  
  21.     return calculate_discounts(book_counts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement