/
SpawNox
/
CookBook
Обзор
Документация
Войти
/
SpawNox
/
CookBook
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
main.py
29 строк
1 KB
SpawNox
upload files
21 июн 2025, 11:16
21 июн 2025, 11:16
8dc322d
Код
Авторство
О чём код?
def get_shop_list_by_dishes(dishes, person_count): list_buy = {} for one_dish in dishes: if one_dish not in dishes: print(f'Блюдо {one_dish} отсутствует в кулинарной книге') continue for name in cook_book[one_dish]: if name['ingredient_name'] not in list_buy.keys(): list_buy[name['ingredient_name']] = {'measure': name['measure'], 'quantity': name['quantity'] * person_count} else: new_quantity = list_buy[name['ingredient_name']]['quantity'] + name['quantity'] * person_count list_buy[name['ingredient_name']] = {'measure': name['measure'], 'quantity': new_quantity} return list_buy with (open('recipes.txt', encoding='utf-8') as f): recipies = f.read().split('\n\n') cook_book = {} for dishes in recipies: dish = dishes.split('\n')[0] ingredients = [] for ingredient in dishes.split('\n')[2:]: ingredient_name, quantity, measure = ingredient.split(' | ') ingredients.append({'ingredient_name': ingredient_name, 'quantity': int(quantity), 'measure': measure}) cook_book.setdefault(dish, ingredients) print(cook_book) print(get_shop_list_by_dishes(['Запеченный картофель', 'Омлет'], 2))