Generation

generate functionSun, 11 Dec 2022

Write a program that will ask the user for 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! cook_book = { 'salad': [ {'ingridient_name': 'cheese', 'quantity': 50, 'measure': 'g'} {'ingridient_name': 'tomatoes', 'quantity': 2, 'measure': 'pcs'} {'ingridient_name': 'cucumbers', 'quantity': 20, 'measure': 'g'} ], 'pizza': [ {'ingridient_name': 'cheese', 'quantity': 20, 'measure': 'gr'} {'ingridient_name': 'sausage', 'quantity': 30, 'measure': 'gr'} ], 'lemonade': [ {'ingridient_name': 'lemon', 'quantity': 1, 'measure': 'pcs'} {'ingridient_name': 'water', 'quantity': 200, 'measure': 'ml'} {'ingridient_name': 'sugar', 'quantity': 10, 'measure': 'g'} ] } Enter the number of servings: 3 Result: Cheese: 210 gr. Tomatoes: 6 pcs. Cucumbers: 60g

def total_ingridients(cook_book): dish = input("Enter dish: ") ingridients = cook_book[dish] for i in ingridients: for value in i.values(): print(value) total_ingridients(cook_book)

Questions about programming?Chat with your personal AI assistant