From 77e1d4d3aa47c3d6066ca50faa6eef6d0fe173e8 Mon Sep 17 00:00:00 2001 From: Ardor Date: Thu, 7 May 2026 13:52:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=B8=D0=B8=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0,=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20=D0=BD=D0=B0=20=D0=BE=D1=82?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B?= =?UTF-8?q?=D0=B5=20=D0=BF=D1=83=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zadanie_1.py | 56 +++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/zadanie_1.py b/zadanie_1.py index 3ba73d8..0a062ad 100644 --- a/zadanie_1.py +++ b/zadanie_1.py @@ -2,33 +2,35 @@ 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 - }) + try: + 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 + try: + user_id = int(parts[0].strip()) + item_name = parts[1].strip() + quantity = int(parts[2].strip()) + price = float(parts[3].strip()) + except ValueError: + continue + total = quantity * price + orders.append({ + 'user_id': user_id, + 'item_name': item_name, + 'quantity': quantity, + 'price': price, + 'total': total + }) + except FileNotFoundError: + print(f"Ошибка: файл {filepath} не найден.") + except Exception as e: + print(f"Ошибка при чтении файла: {e}") return orders @@ -156,7 +158,7 @@ def save_report(filepath: str, report_text: str) -> bool: def main(): print("=== Система анализа заказов интернет-магазина ===\n") - data_dir = r"C:\Users\Ardor\Desktop\Практика\others" + data_dir = "data" # Создаем папку, если её нет os.makedirs(data_dir, exist_ok=True)