A simple command-line expense tracker built with Python. This project allows users to record, view, delete, and calculate their expenses while storing the data in a JSON file.
- Add new expenses
- View all recorded expenses
- Delete an expense
- Calculate total expenses
- Save expenses to a JSON file
- Load saved expenses when the program starts
- Handle invalid user input
-
Python 3
-
JSON for data storage
-
Python built-in functions such as:
jsoninput()try/except- Lists
- Dictionaries
- Functions
- Loops
- Conditional statements
python-expense-tracker/
│
├── expense_tracker.py
├── expenses.json
└── README.md
expenses.jsonis used to store the expense data.
git clone https://github.com/your-username/python-expense-tracker.gitcd python-expense-trackerpython expense_tracker.pyWhen the program starts, the user is presented with a menu:
--- Expense Tracker ---
1. Add expense
2. View expenses
3. Delete expense
4. View total
5. Quit
The user enters a description and amount.
Enter expense description: Food
Enter expense amount: 50
Expense added: Food for GHC50.00
The user can view all recorded expenses:
1. Food for GHC50.00
2. Transport for GHC20.00
3. Internet for GHC100.00
The user selects an expense by its number:
Enter the number of the expense to delete: 2
Removed expense: Transport
The program calculates the total amount spent:
Total expenses: GHC150.00
The application uses a JSON file called expenses.json to store expenses.
Example:
[
{
"description": "Food",
"amount": 50.0
},
{
"description": "Internet",
"amount": 100.0
}
]This allows expenses to remain saved even after the program is closed.
The program includes basic error handling to prevent invalid input from crashing the application.
For example, if the user enters text instead of a number for an expense amount:
Invalid amount. Please enter a valid number.
The program also checks that the user selects a valid expense number when deleting an expense.
Building this project helped me practice:
- Python functions
- Lists and dictionaries
whileloopsif/elifconditional statements- Exception handling with
try/except - Reading and writing JSON files
- Working with user input
- Basic data persistence
- Structuring a small Python application
Some features I may add in the future include:
- Expense categories
- Dates for each expense
- Monthly expense summaries
- Search and filter functionality
- A graphical user interface
- Exporting expense reports
- Budget tracking
Built with Python as a practical project to improve programming and problem-solving skills.