/
angry_code
/
PYAPI_Homework_angry-code
Обзор
Документация
Войти
/
angry_code
/
PYAPI_Homework_angry-code
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
task_1-2_angry-code.py
32 строки
1 KB
angry_code
update: task_1-2_angry-code.py
26 апр 2026, 20:43
Верифицирован
26 апр 2026, 20:43
d2c596f
Код
Авторство
О чём код?
with open('recipes.txt', encoding='UTF8') as f: cook_book = {} i = 0 lines = f.readlines() for __ in lines: if i<len(lines): cook_course = lines[i].strip() total_ingredients = int(lines[i+1]) cook_book[cook_course] = [] for ingredient in lines[i+2: i+2+total_ingredients]: ingredient = ingredient.split('|') part_dish = {} part_dish['ingredient_name'] = ingredient[0] part_dish['quantity'] = ingredient[1] part_dish['measure'] = ingredient[2] cook_book[cook_course].append(part_dish) i = i+total_ingredients+3 def get_shop_list_by_dishes(dishes, person_count): shop_list = {} for dish in dishes: for ingredient in cook_book[dish]: shop_list[ingredient['ingredient_name']] = {'measure':ingredient['measure'].strip(), 'quantity': int(ingredient['quantity'].strip())*person_count} return shop_list print(get_shop_list_by_dishes(['Запеченный картофель', 'Омлет'], 2))