mirror of
https://github.com/blshaer/python-by-example.git
synced 2026-03-27 23:29:25 +01:00
| .. | ||
| README.md | ||
| solution.py | ||
💰 Project 02: Expense Tracker
Difficulty: 🟡 Intermediate
Description
Build a command-line expense tracker that allows users to add, view, and analyze their expenses. Data is saved to a JSON file so expenses persist between sessions.
Requirements
- Add new expenses with a description, amount, and category
- View all expenses in a formatted table
- Filter expenses by category
- Show a summary with total spending and spending per category
- Save and load expenses from a JSON file
- Delete an expense by its ID
Concepts You'll Practice
- Dictionaries and Lists
- File I/O (JSON)
- Functions with multiple parameters
- String formatting
datetimemodule- Data filtering and aggregation
Example Output
💰 EXPENSE TRACKER
==================
1. Add Expense
2. View All Expenses
3. View by Category
4. Summary
5. Delete Expense
6. Exit
Choose an option: 1
Enter description: Coffee
Enter amount: 4.50
Enter category (food/transport/entertainment/bills/other): food
✅ Expense added successfully!
Choose an option: 4
📊 EXPENSE SUMMARY
Total Expenses: $127.50
🍔 Food: $45.00 (35.3%)
🚗 Transport: $32.50 (25.5%)
🎬 Entertainment: $25.00 (19.6%)
📄 Bills: $25.00 (19.6%)
How to Run
cd projects/02_expense_tracker
python solution.py
Bonus Challenges
- Add monthly budget limits with warnings
- Export expenses to CSV
- Add date range filtering