A lightweight, zero-dependency Python console application for tracking expenses in real time. Built around the IPO (Input → Process → Output) model with clean function separation and robust input validation.
- Live running total — updated and displayed after every valid entry
- Full session history — every expense is stored and shown at exit
- Summary report — count, total, average, highest, and lowest expense
- Strict input validation — rejects text, negatives, and zero values without crashing
- Graceful exit — multiple sentinel commands supported
- Currency formatting — all values formatted to two decimal places
| Requirement | Version |
|---|---|
| Python | 3.9 or higher |
| Dependencies | None (standard library only) |
No installation needed. Clone or download the file and run it directly.
# Clone the repo (or just download expense_tracker.py)
git clone https://github.com/your-username/expense-tracker.git
cd expense-trackerpython3 expense_tracker.pyType any positive number and press Enter:
Enter expense amount: 49.99
✔ Added : $49.99
Total : $49.99 (1 expense(s) so far)
Type any of the following and press Enter:
| Command | Effect |
|---|---|
quit |
Exit and show summary |
exit |
Exit and show summary |
done |
Exit and show summary |
q |
Exit and show summary |
========================================
EXPENSE TRACKER 💰
========================================
Type an amount and press Enter.
Type 'quit', 'exit', or 'done' to stop.
========================================
Enter expense amount: 100
✔ Added : $100.00
Total : $100.00 (1 expense(s) so far)
Enter expense amount: 50
✔ Added : $50.00
Total : $150.00 (2 expense(s) so far)
Enter expense amount: abc
⚠ Invalid input. Please enter a numeric value (e.g. 12.50).
Enter expense amount: -20
⚠ Negative values are not allowed. Enter a positive amount.
Enter expense amount: 75.50
✔ Added : $75.50
Total : $225.50 (3 expense(s) so far)
Enter expense amount: quit
Exiting… generating your report.
========================================
EXPENSE SUMMARY REPORT
========================================
Expenses : ['$100.00', '$50.00', '$75.50']
Count : 3 expense(s)
Total Spent : $225.50
Average : $75.17
Highest : $100.00
Lowest : $50.00
========================================
Thank you for using Expense Tracker. Goodbye! 👋
| Input | Behaviour |
|---|---|
| Valid positive number | Accepted and recorded |
Zero (0) |
Rejected — not a meaningful expense |
| Negative number | Rejected with a warning |
| Text / letters | Rejected with a friendly error message |
| Sentinel word | Triggers exit and summary |
The program never crashes on bad input — all error paths are handled inside validate_input().
expense_tracker.py
│
├── validate_input(raw) # INPUT — parses and validates a raw string
├── add_expense(expenses, amount) # PROCESS — appends to list, returns new total
├── display_summary(expenses) # OUTPUT — prints the end-of-session report
└── main() # ORCHESTRATOR — runs the while loop
Each function has a single, well-defined responsibility. The IPO model is applied at both the function level and the overall program level.
sum(expenses) over a running += accumulator
A += pattern silently produces wrong totals if expenses are ever removed or edited. Recomputing with sum() is always correct and negligibly slower for typical session sizes.
Optional[float] return from validate_input
Returning None on failure is unambiguous. Returning -1 or "" would be sentinel-within-sentinel hacks that obscure intent.
Zero rejection
A $0.00 expense is a logic error, not just a type error. Accepting it would corrupt the average and pollute the history.
Empty-list guard in display_summary
max([]) and min([]) raise ValueError in Python. The guard handles the case where a user exits immediately without entering any data.
- No persistence — data is lost when the program exits. A future version could append to a CSV file.
- No categories — all expenses are a flat list. Grouping by category would require a dict or dataclass.
- No editing — once entered, an expense cannot be removed or corrected within the same session.
MIT — free to use, modify, and distribute.