Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def shopping_list(budget, **kwargs):
- bought_items = {}
- result = ''
- if budget < 100:
- return f"You do not have enough budget."
- while budget > 0 and len(bought_items) <= 5:
- for item, data in kwargs.items():
- price, quantity = data[0], data[1]
- if price * quantity > budget:
- continue
- bought_items[item] = price * quantity
- budget -= price * quantity
- if budget == 0 or len(bought_items) == 5:
- break
- break
- for b_item, value in bought_items.items():
- result += f'You bought {b_item} for {value:.2f} leva.'+'\n'
- return result
- print(shopping_list(104,
- cola=(1.20, 2),
- candies=(0.25, 15),
- bread=(1.80, 1),
- pie=(10.50, 5),
- tomatoes=(4.20, 1),
- milk=(2.50, 2),
- juice=(2, 3),
- eggs=(3, 1),
- ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement