Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Python Expense Tracker 💰

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.

📌 Features

  • 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

🛠️ Technologies Used

  • Python 3

  • JSON for data storage

  • Python built-in functions such as:

    • json
    • input()
    • try/except
    • Lists
    • Dictionaries
    • Functions
    • Loops
    • Conditional statements

📂 Project Structure

python-expense-tracker/
│
├── expense_tracker.py
├── expenses.json
└── README.md

expenses.json is used to store the expense data.

🚀 How to Run

1. Clone the repository

git clone https://github.com/your-username/python-expense-tracker.git

2. Open the project folder

cd python-expense-tracker

3. Run the program

python expense_tracker.py

📋 How It Works

When 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

Add an Expense

The user enters a description and amount.

Enter expense description: Food
Enter expense amount: 50

Expense added: Food for GHC50.00

View Expenses

The user can view all recorded expenses:

1. Food for GHC50.00
2. Transport for GHC20.00
3. Internet for GHC100.00

Delete an Expense

The user selects an expense by its number:

Enter the number of the expense to delete: 2

Removed expense: Transport

View Total

The program calculates the total amount spent:

Total expenses: GHC150.00

💾 Data Storage

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.

🛡️ Input Validation

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.

🎯 What I Learned

Building this project helped me practice:

  • Python functions
  • Lists and dictionaries
  • while loops
  • if/elif conditional statements
  • Exception handling with try/except
  • Reading and writing JSON files
  • Working with user input
  • Basic data persistence
  • Structuring a small Python application

🔮 Future Improvements

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.

About

A simple Python expense tracker that allows users to add, view, delete, and calculate expenses using JSON file storage.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages