Kodewick
Start learning →
Basic←→0 / 100

Cart total

#063BasicDictsLoops4 min

The stationery shop has prices (item to price), and your cart is item to how many. Write cart_total(prices, cart) to return what it all costs. Everything in the cart has a price; an empty cart costs 0.

Examples
cart_total({"pen": 3, "book": 10, "eraser": 1}, {"pen": 2, "book": 1})→16
cart_total({"pen": 3, "book": 10}, {"book": 3})→30
main.py
def cart_total(prices, cart):
    total = 0
    for item, qty in cart.items():
        # your code here: price times qty, added to total
        pass
    return total
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.