Add-to-cart helper
Python · FastAPI · beginner · greenfield
Adds the cart helper: appends the item and returns the cart, defaulting to a fresh empty cart when none is passed. Verified by adding a couple of items.
Requirements
- add_item(name, cart=...) appends an item and returns the cart.
- Called with no cart, it must start from an empty cart.
- Two independent calls with no cart must not share state.
Files touched
- app/cart.py
--- app/cart.py +def add_item(name: str, cart: list[str] = []) -> list[str]: + cart.append(name) + return cart