Generation

generate functionSun, 11 Dec 2022

A recipe book is given with information about how many ingredients are needed to prepare a dish per serving. Write a program that will multiply the number of servings to prepare these dishes and display the information about the total amount of ingredients required in the given form. Note: The same ingredients with different dimensions must be counted separately! Example: dish = 'salad' portions = 5 The result should be: Cheese: 250 g Tomatoes: 10 pcs. Cucumbers: 60g cook_book = {'salad': [{'ingridient_name': 'cheese', 'quantity': 50, 'measure': 'g'}, {'ingridient_name': 'tomatoes', 'quantity': 2, 'measure': 'pcs'}, {'ingridient_name': 'cucumbers', 'quantity': 100, 'measure': 'g'}]}

def get_ingredients(dish, portions): recipes = cook_book.get(dish, []) if not recipes: print('No such dish') return print(f'You need to cook {dish} for {portions} portions') for recipe in recipes: print(f'{recipe["ingridient_name"]}: {recipe["quantity"] * portions} {recipe["measure"]}')

Questions about programming?Chat with your personal AI assistant