Question: Complete the shopping() function, which takes two arguments: a dictionary that maps store products to prices (the keys are strings that represent product names, while
Complete the shopping() function, which takes two arguments: a dictionary that maps store products to prices (the keys are strings that represent product names, while the values are integers representing the product prices) and a list of products (strings)thatapersonwantstobuy. The list might contain products not for sale at the store. The function uses the dictionary and the list to compute how much the shopping trip will cost.
As an example, suppose the dictionary products is dened as {"toothbrush": 2, "comb": 3, "soap": 5, "brush": 7, "shampoo": 10} and the list shopping_list is dened as ["shampoo", "brush", "shampoo", "soap", "soap", "dog food", "soap"]
For these inputs, shopping(products, shopping_list) will return 42. Note that the item "dog food" is not for sale at the store,yet the function can still compute and return the total without crashing. Also note that someitems(shampoo and soap) were purchased multiple times; this is reected in the total cost. You may assume that product names are CASE-SENSITIVE.
QUESTION: FunctionCall ({"shampoo": 10, "soap": 5, "comb": 3, "brush": 7, "toothbrush": 2}, ["shampoo", "brush", "shampoo", "soap", "soap", "dog food", "soap"]) RETURN VALUE-42. shopping({"shampoo": 10, "soap": 5, "comb": 3, "brush": 7, "toothbrush": 2}, ["candy", "brush", "brush", "soap", "fruit", "soap"]) RETURN VALUE-24. shopping({"shampoo": 10, "soap": 5, "comb": 3, "brush": 7, "toothbrush": 2}, ["wood", "paint", "shovel", "mop"])RETURN VALUE- 0.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
