/
evinbits
/
123
Обзор
Документация
Войти
/
evinbits
/
123
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
12345.py
76 строк
3 KB
EVI
Initial commit
03 июл 2025, 11:51
03 июл 2025, 11:51
cd87d9d
Код
Авторство
О чём код?
cook_book = { 'Омлет': [ {'ingredient_name': 'Яйцо', 'quantity': 2, 'measure': 'шт.'}, {'ingredient_name': 'Молоко', 'quantity': 100, 'measure': 'мл'}, {'ingredient_name': 'Помидор', 'quantity': 2, 'measure': 'шт'} ], 'Утка по-пекински': [ {'ingredient_name': 'Утка', 'quantity': 1, 'measure': 'шт'}, {'ingredient_name': 'Вода', 'quantity': 2, 'measure': 'л'}, {'ingredient_name': 'Мед', 'quantity': 3, 'measure': 'ст.л'}, {'ingredient_name': 'Соевый соус', 'quantity': 60, 'measure': 'мл'} ], 'Запеченный картофель': [ {'ingredient_name': 'Картофель', 'quantity': 1, 'measure': 'кг'}, {'ingredient_name': 'Чеснок', 'quantity': 3, 'measure': 'зубч'}, {'ingredient_name': 'Сыр гауда', 'quantity': 100, 'measure': 'г'}, ] } def get_shop_list_by_dishes(dishes, person_count): shop_list = {} for dish in dishes: if dish in cook_book: for ingredient in cook_book[dish]: ingredient_name = ingredient['ingredient_name'] quantity = ingredient['quantity'] * person_count measure = ingredient['measure'] if ingredient_name in shop_list: shop_list[ingredient_name]['quantity'] += quantity else: shop_list[ingredient_name] = {'measure': measure, 'quantity': quantity} else: print(f"Блюдо '{dish}' не найдено в кулинарной книге.") return shop_list import os def combine_files(file_list, output_file): file_data = [] for filename in file_list: try: with open(filename, 'r', encoding='utf-8') as f: lines = f.readlines() file_data.append((filename, len(lines), lines)) except FileNotFoundError: print(f"Файл '{filename}' не найден.") return file_data.sort(key=lambda x: x[1]) with open(output_file, 'w', encoding='utf-8') as outfile: for filename, line_count, lines in file_data: outfile.write(f"{filename}\n") outfile.write(f"{line_count}\n") outfile.writelines(lines) with open("1.txt", "w", encoding="utf-8") as f: f.write("Строка номер 1 файла номер 1\n") f.write("Строка номер 2 файла номер 1\n") with open("2.txt", "w", encoding="utf-8") as f: f.write("Строка номер 1 файла номер 2\n") combine_files(["1.txt", "2.txt"], "output.txt") with open("output.txt", "r", encoding="utf-8") as f: print(f.read()) os.remove("1.txt") os.remove("2.txt") os.remove("output.txt")