Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- base_price = 800
- discounts = [ 0, .05, .10, .20, .25]
- def calculate_discounts(book_counts):
- book_count = 0
- for k, v in book_counts.items():
- if v > 0:
- book_counts[k] -= 1
- book_count += 1
- if book_count == 0:
- return 0
- print(f"Books: {book_count} * Base Price: {base_price} * Discount: {discounts[book_count-1]}")
- return book_count * base_price * (1-discounts[book_count-1]) + calculate_discounts(book_counts)
- def total(basket):
- book_counts = {}
- for i in basket:
- book_counts[i] = book_counts.get(i, 0) + 1
- return calculate_discounts(book_counts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement