From 4a318c94f3a2e1966822f673733ccf28fc0be858 Mon Sep 17 00:00:00 2001 From: Ardor Date: Thu, 7 May 2026 13:10:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F=20loa?= =?UTF-8?q?d=5Forders?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zadanie_1.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/zadanie_1.py b/zadanie_1.py index 8d1c8b6..f03aa22 100644 --- a/zadanie_1.py +++ b/zadanie_1.py @@ -1 +1,32 @@ - +import os + +# 1. Загрузка заказов из файла +def load_orders(filepath: str) -> list[dict]: + """ + Читает файл с заказами. + Формат строки: user_id, item_name, quantity, price_per_item + """ + orders = [] + with open(filepath, 'r', encoding='utf-8') as file: + for line in file: + line = line.strip() + if not line: + continue + parts = line.split(',') + if len(parts) != 4: + continue + + user_id = int(parts[0].strip()) + item_name = parts[1].strip() + quantity = int(parts[2].strip()) + price = float(parts[3].strip()) + total = quantity * price + + orders.append({ + 'user_id': user_id, + 'item_name': item_name, + 'quantity': quantity, + 'price': price, + 'total': total + }) + return orders