What you'll build
Build a small shopping list, then use every list move from the lesson — indexing, slicing, append, remove, in. Short but covers the ground.
Requirements
The must-do parts. If any are missing, we'll ask you to take another pass.
- Start with a list of at least eight grocery items (tomatoes, onion, garri, milo, bread, eggs, plantain, gari foto — yours can be different).
- Print the first item, the last item, and items at positions 2 to 5 using slicing.
- Append one new item and remove a different one. Print the list before and after.
- Check whether
"rice"is in the list usinginand print a sentence saying so.
Bonus, if you're feeling brave
- Print the list sorted alphabetically without changing the original.
- Print the total number of items as a single labelled line.
Where to start
Copy this scaffold into a new file. You don't have to use it — it's just a friendly nudge.
market_basket.py
items = [
"tomatoes",
"onion",
"garri",
"milo",
"bread",
"eggs",
"plantain",
"gari foto",
]
# TODO: print first item, last item, and a slice of the middle
# TODO: append one item, remove another, print before and after
# TODO: check if "rice" is in the list and print a sentenceHow we'll grade it
Four checks, four points. Three or above is passing — we'll ask you to revise anything we can't tick.
| Check | What we look for | Pt |
|---|---|---|
| It runs | Top to bottom on a fresh notebook, no errors. | 1 |
| Indexes and slices | First, last, and the middle slice all show the right items. | 1 |
| Changes the list | The list looks different after append and remove. | 1 |
| Membership check | `in` is used and the printed sentence reads naturally. | 1 |