Lab walkthrough: CLI Expense Tracker
Try to build it yourself first, using the spec in the README. If you get stuck, follow this path, then compare your version with the reference solution in lab/expense_tracker.py.
Step 1: plan the functions. Before writing code, write the function names as comments:
Step 2: the menu loop. Get main() working with while True, input, if/elif and break, printing a placeholder for each option. Run it.
Step 3: add and list. Store each expense as a dict. Use try/except ValueError around float(input(...)). Use enumerate(expenses, start=1) and f-string alignment to print a neat table.
Step 4: totals. Use the counting pattern from Lesson 1.7. Print the categories in sorted order, then a grand total using sum(e["amount"] for e in expenses).
Step 5: persistence. Add load_expenses and save_expenses from Lesson 1.8. Call load once at start-up and save after every change.
Step 6: ship it. Add a README.md (what it does, how to run it, a sample of the output), a .gitignore (including expenses.json if you don't want to publish your spending), commit and push.
The last line of the file: if __name__ == "__main__": main() means "run main() only when this file is executed directly, not when another file imports it". You'll see it in almost every Python script.