Добавлена функция validate_orders

This commit is contained in:
Антон Репин 2026-05-07 13:12:14 +03:00
parent 4a318c94f3
commit 0cf7622346

View File

@ -30,3 +30,17 @@ def load_orders(filepath: str) -> list[dict]:
'total': total
})
return orders
# 2. Валидация заказов (удаление некорректных)
def validate_orders(orders: list[dict]) -> list[dict]:
"""
Отбрасывает заказы с quantity <= 0, price <= 0 или пустым item_name.
"""
valid_orders = []
for order in orders:
if (order['quantity'] > 0 and
order['price'] > 0 and
order['item_name'].strip() != ''):
valid_orders.append(order)
return valid_orders