Generation

generate functionSun, 11 Dec 2022

Write a function that multiplies each dictionary value by portions 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 multiply(dictionary): for i in dictionary[key]: i['quantity'] = i['quantity'] * portions return dictionary multiply(cook_book)

Questions about programming?Chat with your personal AI assistant