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) The result should be: Cheese: 210 g Tomatoes: 6 pcs. Cucumbers: 60g Olives: 30 g Olive oil: 60 ml Lettuce: 30 gr Pepper: 60 gr

def get_shop_list_by_dishes(dishes, person_count): shop_list = {} for dish in dishes: for ingridient in cook_book[dish]: new_shop_list_item = dict(ingridient) new_shop_list_item['quantity'] *= person_count if new_shop_list_item['ingridient_name'] not in shop_list: shop_list[new_shop_list_item['ingridient_name']] = new_shop_list_item else: shop_list[new_shop_list_item['ingridient_name']]['quantity'] +=\ new_shop_list_item['quantity'] return shop_list def print_shop_list(shop_list): for shop_list_item in shop_list.values(): print('{} {} {}'.format(shop_list_item['ingridient_name'], shop_list_item['quantity'], shop

Questions about programming?Chat with your personal AI assistant