1def total(items):
2 s = 0
●3 for i in items:
4 s += i["price"]
5 return s
6
7cart = [{"price": 4}, {"cost": 2}]
8
9def checkout():
10 return total(cart)
11
12checkout()
1from cart import total
2
3def test_total_adds_prices():
4 assert total([{"price": 4}, {"price": 6}]) == 10
5
6def test_total_of_nothing_is_zero():
7 assert total([]) == 0
1# cart
2
3A tiny sample project for the dvlpit. demo.
4
5Run cart.py to add up a shopping cart.
6Everything in this project is made up.
CLAIRE. READING ALONG
reading cart.py. the cart has two items.
CALL STACK
total · cart.py:3
checkout · cart.py:10
<module> · cart.py:12
VARIABLES
items = list[2]
s = 0
CONSOLE
> paused at line 3