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 of program operation: portions = 5 grams = 0 key = 'salad' cook_book = {'salad': [{'ingridient_name': 'cheese', 'quantity': 50, 'measure': 'g'}, {'ingridient_name': 'tomatoes', 'quantity': 2, 'measure': 'pcs'}, {'ingridient_name': 'cucumbers', 'quantity': 100, 'measure': 'g'}]} if key == 'salad': grams = 'quantity' * portions print(grams) The result should be: Cheese: 250 g Tomatoes: 10 pcs. Cucumbers: 60g

def get_quantity(cook_book, key, portions): grams = 0 if key == 'salad': grams = cook_book[key][0]['quantity'] * portions print(f"{cook_book[key][0]['ingridient_name']}: {grams} {cook_book[key][0]['measure']}") grams = cook_book[key][1]['quantity'] * portions print(f"{cook_book[key][1]['ingridient_name']}: {grams} {cook_book[key][1]['measure']}") grams = cook_book[key][2]['quantity'] * portions print(f"{cook_book[key][2]['ingridient_name']}: {grams} {cook_book[key][2]['measure']}")

Questions about programming?Chat with your personal AI assistant