Mission Log can load and save, but nobody can use it yet. Rocket wants the menu working today, even though only one feature is built.
"What happens if someone picks List?" he asks. "That part does not exist yet."
Raven thinks of the construction signs on the road outside. "What do you notice about a road that is still being built?" she asks. "It is open where it is finished, and has a sign where it is not."
Nova displays a small sign that reads Coming soon. "Interesting," she says. "Programmers call that a stub. The whole menu works today, and each stub is replaced when its feature is ready."
Rocket deletes the temporary test lines and starts on main.
add_entry asks two questions. If the text is empty, it saves nothing. If the tag is empty, it uses note. Then it adds today's date with date.today().isoformat(), saves the whole list and reports the entry number.
Type it below make_entry in your file.
def add_entry(entries):
"""Ask for a new entry, add it to the list and save."""
text = input("What happened? ").strip()
if text == "":
print("Nothing typed, so nothing saved.")
return
tag = input("Tag (build, test, idea): ").strip().lower()
if tag == "":
tag = "note"
entries.append(make_entry(text, tag, date.today().isoformat()))
save_entries(entries)
print(f"Saved entry {len(entries)}.") main loads the log once, then loops: show the menu, ask for a choice, run it. Choices 2 to 4 are stubs for now. Anything else gets a polite message.
Type main below add_entry. Then add the last two lines at the very bottom, so main runs when you run the file.
def main():
"""Load the log, then show the menu until the user quits."""
entries = load_entries()
print(f"Mission Log ready. Entries loaded: {len(entries)}")
while True:
print()
print("1 Add 2 List 3 Search 4 Stats 5 Quit")
choice = input("Choose 1 to 5: ").strip()
if choice == "1":
add_entry(entries)
elif choice == "5":
print("Log saved. See you next mission!")
break
elif choice in ["2", "3", "4"]:
print("Coming soon.")
else:
print("Please type a number from 1 to 5.") if __name__ == "__main__":
main() Delete mission_log.json first so your log starts empty. Here is a run where the user adds one entry, tries an empty one, picks a stub, types 7 and then quits:
Mission Log ready. Entries loaded: 0 1 Add 2 List 3 Search 4 Stats 5 Quit Choose 1 to 5: 1 What happened? Built the menu Tag (build, test, idea): Build Saved entry 1. 1 Add 2 List 3 Search 4 Stats 5 Quit Choose 1 to 5: 1 What happened? Nothing typed, so nothing saved. 1 Add 2 List 3 Search 4 Stats 5 Quit Choose 1 to 5: 2 Coming soon. 1 Add 2 List 3 Search 4 Stats 5 Quit Choose 1 to 5: 7 Please type a number from 1 to 5. 1 Add 2 List 3 Search 4 Stats 5 Quit Choose 1 to 5: 5 Log saved. See you next mission!
| Statement | True or false? |
|---|---|
| A stub lets the menu work before a feature is built. | ? |
| return with no value ends add_entry early. | ? |
| The menu loop is a while True loop with a break. | ? |
| Typing 7 at the menu stops the program with an error. | ? |
Mission Log now has a real menu and saves every entry. Tomorrow you will replace the first stub with the List feature.