stage24-store-payments.py
TEXT FILE557 B · Public source code for developers, search crawlers and AI agents
1def total(catalog, cart):
2 if not cart: raise ValueError("empty cart")
3 result = 0
4 for sku, qty in cart.items():
5 price = catalog[sku]
6 if type(qty) is not int or type(price) is not int or not 1 <= qty <= 100 or price <= 0:
7 raise ValueError("invalid item")
8 result += price * qty
9 return result
10
11if __name__ == "__main__":
12 assert total({"book": 1200}, {"book": 2}) == 2400
13 try: total({"book": 1200}, {"book": -1})
14 except ValueError: pass
15 else: raise AssertionError("negative quantity accepted")Read-only source · Select a line number to link directly · Raw download above
