▶ Sign up free for the video, slides & prompts
The lesson below is open to all. Enter your email once to unlock every video, slide deck, prompt and code example on this device.
Checking…
Mini project: expense tracker
Save expenses to a CSV and print monthly totals.
🎬 Video version coming soon — read it now
Let's build a small app you might actually use daily: an expense tracker that saves to a CSV file, so your data survives after the program closes.
Features
- Add an expense: date, category, amount and note
- List all expenses
- Show totals per category for any month
- Data stored in
expenses.csv, so you can also open it in Excel
The code
How it fits together
- pathlib checks whether the file exists; csv reads and writes it
- datetime stamps each expense; ISO dates (
2026-12-06) sort correctly and make month filtering a simplestartswith - Mode
"a"appends, and the header is written only once - The same dictionary-of-functions menu idea from the unit converter
Run it on your laptop (python expenses.py) so the CSV stays between runs, then open expenses.csv in Excel.
Challenges
- Add a monthly budget per category and warn when you go over.
- Let the user enter a date instead of always using today.
- Export the monthly report to a JSON file.
- Add a "delete last expense" option. Hint: load, remove the last item, rewrite the whole file with
"w".
What you learned in this course
- Text, CSV and JSON files, and the with statement
- Modules, import and the standard library
- pip, requirements.txt and virtual environments
- Running Python on your own laptop, and automating tasks safely with AI
Next course: Objects & Classes. You'll learn to model real things, such as bank accounts, students and products, as objects.
In one line
You built an app that saves data between runs, using csv, pathlib, datetime and clean functions.
Share with a friend