
Checkpoint
Checkpoint: The Lamplighter's Cart
Every evening the lamplighters roll their carts across the
bridges, loaded with fresh lamps. The Guild wants a Cart class
to keep track of them.
This checkpoint uses the whole chapter: __init__, methods,
self, a class attribute, __str__ and __repr__.
Assignment
Complete the Cart class:
__init__(self, owner)storesownerand gives every cart its own emptylampslist.- Each new cart adds 1 to the class attribute
Cart.built. load(lamp)addslampto the end oflampsand returns how many lamps the cart now holds.unload()removes the last lamp and returns it. If the cart is empty, it returnsNone.__str__returns text likeAda's cart: 2 lamps.__repr__returns text likeCart('Ada').
Complete the Cart class:
__init__(self, owner)storesownerand gives every cart its own emptylampslist.- Each new cart adds 1 to the class attribute
Cart.built. load(lamp)addslampto the end oflampsand returns how many lamps the cart now holds.unload()removes the last lamp and returns it. If the cart is empty, it returnsNone.__str__returns text likeAda's cart: 2 lamps.__repr__returns text likeCart('Ada').
main.py Python sleeping
Press Run to try your code, then Check to test it.