Добавлена функция apply_discount
This commit is contained in:
parent
3b7d5d6f6e
commit
94d132aa97
14
zadanie_1.py
14
zadanie_1.py
@ -77,3 +77,17 @@ def find_most_expensive_item(orders: list[dict]) -> tuple[str, float]:
|
|||||||
return ('', 0.0)
|
return ('', 0.0)
|
||||||
most_expensive = max(orders, key=lambda x: x['price'])
|
most_expensive = max(orders, key=lambda x: x['price'])
|
||||||
return (most_expensive['item_name'], most_expensive['price'])
|
return (most_expensive['item_name'], most_expensive['price'])
|
||||||
|
|
||||||
|
|
||||||
|
# 6. Применение скидки ко всем заказам (возвращает новый список)
|
||||||
|
def apply_discount(orders: list[dict], discount_percent: float) -> list[dict]:
|
||||||
|
"""
|
||||||
|
Уменьшает поле 'total' на discount_percent.
|
||||||
|
Возвращает новый список заказов, не изменяя исходный.
|
||||||
|
"""
|
||||||
|
discounted_orders = []
|
||||||
|
for order in orders:
|
||||||
|
new_order = order.copy()
|
||||||
|
new_order['total'] = order['total'] * (1 - discount_percent / 100.0)
|
||||||
|
discounted_orders.append(new_order)
|
||||||
|
return discounted_orders
|
||||||
Loading…
Reference in New Issue
Block a user