Contact book
Pip Hey! I've got contacts scattered across six stations and I keep losing track of them. Numbers, emails, all over the place. Can you build a simple contact book I can run in a terminal? Add people, search by name, list everyone. Nothing fancy, just something that actually works 🙏
What you're building
Commands: add / search / list / quit
> add
Name: Alice Johnson
Phone: 07700 900123
Email: [email protected]
Saved.
> search
Name: alice
Alice Johnson — 07700 900123 — [email protected]
> list
1. Alice Johnson — 07700 900123
2. ...
> quitWhat you'll need
- Dictionaries — each contact is a dictionary; the contact book is a list of them
- Lists — all contacts together in one list you can loop through
- Functions — one function per command keeps things clean and readable
- Control flow — a loop that runs until the user types "quit"
- Strings — case-insensitive searching, name formatting
Hints
Store each contact as a dictionary. Keys like "name", "phone", "email". Keep all contacts in a list outside the loop so they persist between commands.
A while loop with a command check is the natural structure. Read the command, call the right function, repeat. Break out when the user types "quit".
For search, partial matching is more useful than exact. Checking if the search term appears anywhere in the name — case-insensitively — means "alice" finds "Alice Johnson".
Going further
Once the core loop works:
- Save and load. When the user quits, write all contacts to a JSON file. When the script starts, load that file if it exists. This requires the files chapter.
- Delete a contact. Add a
deletecommand that removes a contact by name. - Sorted list. Sort the list output alphabetically by name before printing.

