fruit_prices maps a fruit name to its price. purchases is a list of
(fruit, quantity) tuples.
Write total_price(fruit_prices, purchases) that returns the total cost of the
purchase: for every tuple, multiply the price of the fruit by the quantity, and
add all of these up. A fruit may appear in more than one tuple. An empty
purchases list costs 0.
Use an explicit loop -- do not use the sum function.
Example
total_price({'Apple': 2, 'Banana': 3}, [('Apple', 2), ('Banana', 1)]) returns 7.
Implement this function:
def total_price(fruit_prices: dict, purchases) -> float:
Write the function only — the arguments are read for you and the return value is printed automatically.
Arguments arrive as one Python literal per line, in this order: fruit_prices, purchases.
Input
{'Apple': 2, 'Banana': 3}
[('Apple', 2), ('Banana', 1)]
Output
7