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': 'gr'}, {'ingridient_name': 'tomatoes', 'quantity': 2, 'measure': 'pct'}, {'ingridient_name': 'pepper', 'quantity': 20, 'measure': 'гр'}]} if key == 'salad': grams = 'quantity' * portions print(grams)

def multiply_dict(key): grams = 0 cook_book = {'salad': [{'ingridient_name': 'cheese', 'quantity': 50, 'measure': 'gr'}, {'ingridient_name': 'tomatoes', 'quantity': 2, 'measure': 'pct'}, {'ingridient_name': 'pepper', 'quantity': 20, 'measure': 'гр'}]} if key == 'salad': grams = cook_book.get('salad')[0].get('quantity') * 5 print(grams) multiply_dict('salad')

Questions about programming?Chat with your personal AI assistant