The flight director has a request for the crew: a tool for keeping a log of every mission. It should add notes, list them, search them and count them, and it must never lose a note.
Rocket is already typing. "I have an idea! A menu, a loop, a file, and..." He stops. "Actually, where do I even start?"
Raven pulls the whiteboard over. "What do you notice about the request?" she asks. "It is four features and one rule. That is five small problems, not one big one."
Nova draws five boxes on the whiteboard and an arrow from each to a single file. "Would you like a hint?" she asks. "Decide what one entry looks like first. Every feature uses the same data."
Rocket puts down the keyboard and picks up a marker.
| Feature | Function | Built on |
|---|---|---|
| Load and save the log | load_entries, save_entries | Monday |
| Add an entry | make_entry, add_entry, main | Tuesday |
| List entries | format_entry, show_entries | Wednesday |
| Search | search_entries, run_search | Thursday |
| Count tags | count_tags, show_stats | Friday |
Each entry is a dictionary with three keys: the date, a one-word tag, and the text. The whole log is a list of these dictionaries, saved in mission_log.json. You met this exact shape in week 5.
{"date": "2026-04-12", "tag": "build", "text": "Built the launch clock"} Start a new file called mission_log.py. The first piece loads and saves the log. The function load_entries uses try and except from week 10, so the first run starts empty.
The test lines at the bottom are temporary. They prove the pieces work before anything else is built.
# mission_log.py
# Mission Log: keep dated notes about your missions.
# Entries are saved in mission_log.json, in the same folder.
import json
from datetime import date
LOG_FILE = "mission_log.json"
def load_entries():
"""Read saved entries, or start an empty list on the first run."""
try:
with open(LOG_FILE) as f:
return json.load(f)
except FileNotFoundError:
return []
def save_entries(entries):
"""Write every entry to the JSON file."""
with open(LOG_FILE, "w") as f:
json.dump(entries, f, indent=2)
def make_entry(text, tag, day):
"""Build one entry as a dictionary."""
return {"date": day, "tag": tag, "text": text}
# Temporary test lines: delete them tomorrow.
entries = load_entries()
print("Loaded", len(entries), "entries")
entries.append(make_entry("Planned Mission Log", "idea", "2026-04-12"))
save_entries(entries)
print("Saved", len(entries), "entries") The first run, then the second run:
Loaded 0 entries Saved 1 entries
Loaded 1 entries Saved 2 entries
A plan, a data shape and two working pieces: a strong start. Tomorrow you will build the menu loop and the add feature.