← Intro to programming with Python

Mini project: shopping list

Build a list from input, avoid duplicates, and print it neatly.

Start this lesson

A shopping list app is a list plus a loop plus input. The loop keeps asking for items until the person types done. Each item is tidied, checked so it is not added twice, and appended. At the end, the program prints the list as a numbered checklist. This "read until a stop word" loop is a pattern you will use again and again.

items = []
while True:
    item = input("Item (or done): ").strip().lower()
    if item == "done":
        break
    items.append(item)
print(items)

while True: loops forever on purpose; break is the exit, and it happens when the person types done.

Common mistake: forgetting the break, so "done" never ends the loop and the program asks for more input than there is.

enumerate(items, 1) counts from 1 instead of 0, which is nicer for people reading the list.