Добавлена функция load_orders
This commit is contained in:
parent
a85e343869
commit
4a318c94f3
31
zadanie_1.py
31
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user