Kodewick
Start learning →
Mini challenge←0 / 100

Café order total

#100Mini challengeMixedDicts8 min

Orders come in one line, split by commas, like "Latte, muffin, latte", with careless capitals and spaces. menu is a dict (lower-case name → price). Write order_total(menu, order) to return the total; skip anything not on the menu; an empty order is 0.

Examples
order_total({"latte": 18, "muffin": 12, "tea": 10}, "Latte, muffin, latte")→48
order_total({"latte": 18, "tea": 10}, "TEA, pizza ")→10
order_total({"latte": 18}, "")→0
main.py
def order_total(menu, order):
    total = 0
    for item in order.split(","):
        name = item.strip().lower()
        # your code here: if name is on the menu, add its price
        pass
    return total
Ctrl + Enter runs too
Result

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