34 lines
972 B
Python
34 lines
972 B
Python
# DO NOT CHANGE THE IMPORTS!
|
|
|
|
def calculate_price(articles: dict[str, int], cart: dict[str, int]) -> float:
|
|
price = 0
|
|
for name, amount in cart.items():
|
|
if name in articles:
|
|
price += articles[name] * amount
|
|
return price / 100
|
|
|
|
|
|
def by_amount(articles: dict[str, int], cart: dict[str, int]) -> dict[int, list[str]]:
|
|
out: dict[int, list[str]] = dict()
|
|
for name, amount in cart.items():
|
|
if name not in articles:
|
|
continue
|
|
if amount not in out:
|
|
out[amount] = [name]
|
|
else:
|
|
out[amount] += [name]
|
|
return out
|
|
|
|
|
|
if __name__ == "__main__":
|
|
articles_dict = {"apples": 100, "oranges": 100,
|
|
"lemons": 200, "avocado": 500}
|
|
cart_dict = {"apples": 2, "oranges": 2, "lemons": 1, "bananas": 5}
|
|
|
|
assert calculate_price(articles_dict, cart_dict) == 6.0
|
|
|
|
assert by_amount(articles_dict, cart_dict) == {
|
|
2: ['apples', 'oranges'], 1: ['lemons']}
|
|
|
|
|