AssignmentsWeek 02 · Organizing dataMarket basket — work a list end to end
wk02.p1Practice exerciseWeek 02 · Organizing dataOpen · due in week 2

Market basket — work a list end to end

Build a small shopping list, then use every list move from the lesson — indexing, slicing, append, remove, in. Short but covers the ground.

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.

  1. Start with a list of at least eight grocery items (tomatoes, onion, garri, milo, bread, eggs, plantain, gari foto — yours can be different).
  2. Print the first item, the last item, and items at positions 2 to 5 using slicing.
  3. Append one new item and remove a different one. Print the list before and after.
  4. Check whether "rice" is in the list using in and 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 sentence

How we'll grade it

Four checks, four points. Three or above is passing — we'll ask you to revise anything we can't tick.

CheckWhat we look forPt
It runsTop to bottom on a fresh notebook, no errors.1
Indexes and slicesFirst, last, and the middle slice all show the right items.1
Changes the listThe list looks different after append and remove.1
Membership check`in` is used and the printed sentence reads naturally.1
Ready?
Hand it in
You can submit a draft and revise later if you're not done.
Begin submission →