Skip to content

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’° Python CLI Expense Tracker

Python License Status Type

A menu-driven, console-based expense tracker built entirely with Core Python. Users can log expenses, review their spending history, and see a running total β€” all backed by a simple, dependency-free accumulator pattern.

πŸŽ“ Built as Project 2 of the Python Programming Internship at DecodeLabs, focused on data accumulation, state management, and defensive input handling in backend logic.


πŸ“– Description

The Expense Tracker simulates the core of a real financial ledger: numbers come in one at a time, get validated, and get added to a running total that persists for the life of the session. It's a small program, but it's built around the same fundamental pattern (total += new_value) that powers much larger financial and analytics systems.

The entire application lives in a single, well-documented Python file and uses nothing beyond the standard language β€” no databases, no file storage, no third-party packages.


🏒 Internship Context

Program Python Programming Internship
Organization DecodeLabs
Project Project 2 β€” Expense Tracker
Focus Area Data accumulation & stateful console logic
Constraint Core Python only (no external libraries, no persistence)

✨ Features

  • Add Expense β€” enter an amount and add it to the running total using the accumulator pattern (total += new_expense).
  • View Expense History β€” see every expense recorded during the current session, numbered in the order it was entered.
  • View Total Expenses β€” see the total number of expenses logged and the running total spent.
  • Delete Last Expense β€” remove the most recently added expense and automatically subtract it back out of the total.
  • Reset Expense Tracker β€” clear all recorded expenses and reset the total to zero, with a yes/no confirmation step to prevent accidental data loss.
  • Exit β€” a sentinel-controlled, clean shutdown of the program.

Built-in input safety (every feature is protected by this):

  • Rejects non-numeric input instead of crashing.
  • Rejects negative expense amounts.
  • Rejects empty input and zero-value amounts.
  • Rejects out-of-range or non-numeric menu selections.
  • Gracefully handles Ctrl+C / Ctrl+D (KeyboardInterrupt / EOFError) instead of throwing a raw traceback.

πŸ› οΈ Tech Stack

  • Language: Python 3.x
  • Libraries: None β€” Core Python only (input(), print(), lists, loops, conditionals, functions)
  • Storage: In-memory only (a Python list), scoped to the current session
  • Interface: Command-line / console

πŸ“ Folder Structure

Expense_Tracker_Project/
β”œβ”€β”€ main.py                  # Complete application source code
β”œβ”€β”€ README.md                 # Project documentation (this file)
β”œβ”€β”€ LICENSE                   # MIT License
β”œβ”€β”€ .gitignore                 # Python-specific ignore rules
β”œβ”€β”€ PROJECT_STRUCTURE.md       # Detailed explanation of every file
└── screenshots/                # Real terminal screenshots of the app
    β”œβ”€β”€ home.png
    β”œβ”€β”€ add-expense.png
    β”œβ”€β”€ expense-history.png
    β”œβ”€β”€ total-expenses.png
    β”œβ”€β”€ delete-expense.png
    β”œβ”€β”€ reset-tracker.png
    β”œβ”€β”€ invalid-input.png
    β”œβ”€β”€ negative-expense.png
    └── exit.png

βš™οΈ Installation

Clone the repository:

git clone https://github.com/PawanChoudhary0607/Python-Expense-Tracker.git
cd Python-Expense-Tracker

No dependencies to install β€” the project runs on the Python standard library alone.

Requirements: Python 3.x


▢️ How to Run

python3 main.py

On Windows:

python main.py

πŸ”„ Program Flow

Start
  β”‚
  β–Ό
Display Menu (1-6)
  β”‚
  β–Ό
Read & Validate Menu Choice
  β”‚
  β”œβ”€β”€ 1 β†’ Add Expense        β†’ Validate amount β†’ total += amount
  β”œβ”€β”€ 2 β†’ View History        β†’ Print all recorded expenses
  β”œβ”€β”€ 3 β†’ View Total          β†’ Print count + running total
  β”œβ”€β”€ 4 β†’ Delete Last Expense β†’ Remove last item β†’ total -= amount
  β”œβ”€β”€ 5 β†’ Reset Tracker       β†’ Confirm β†’ Clear list β†’ total = 0
  └── 6 β†’ Exit                β†’ Print goodbye message β†’ break loop
  β”‚
  β–Ό
Loop back to Menu (while True)

πŸ’» Example Output

Welcome to the DecodeLabs Expense Tracker!

==============================
      EXPENSE TRACKER
==============================
1. Add Expense
2. View Expense History
3. View Total Expenses
4. Delete Last Expense
5. Reset Expense Tracker
6. Exit
==============================

Enter your choice (1-6): 1
Enter expense amount: 250

Expense of 250.00 added successfully.
Running Total: 250.00

πŸ“Έ Screenshots

Home Menu

Home Menu

Add Expense

Add Expense

View Expense History

Expense History

View Total Expenses

Total Expenses

Delete Last Expense

Delete Expense

Reset Expense Tracker

Reset Tracker

Invalid Menu Input Handling

Invalid Input

Negative / Invalid Expense Handling

Negative Expense

Exit

Exit


🎯 Learning Outcomes

Building this project reinforced several core backend-engineering concepts:

  • The accumulator pattern β€” how total = total + new_value forms the backbone of any system that processes a continuous stream of numeric data (ledgers, counters, running statistics).
  • State vs. amnesia in loops β€” the importance of initializing state outside a loop so it persists across iterations, rather than resetting it on every pass.
  • Defensive coding β€” treating all user input as untrusted by default, validating type, sign, and emptiness before it ever reaches business logic.
  • Sentinel-controlled program flow β€” using a dedicated exit value to cleanly break out of an otherwise infinite while True loop.
  • Separating logic from display β€” keeping calculation (the "model") distinct from what gets printed to the user (the "view"), even in a single-file script.

πŸš€ Future Improvements

  • Add expense categories (e.g., Food, Travel, Utilities).
  • Persist expenses between sessions (file or database storage).
  • Add date/timestamp tracking for each expense.
  • Add a monthly or weekly spending summary.
  • Add CSV export for use in spreadsheets.

πŸ‘€ Author

Pawan Choudhary B.Tech CSE (AI & ML) Python Programming Intern @ DecodeLabs

GitHub: github.com/PawanChoudhary0607


πŸ“„ License

This project is licensed under the MIT License.

About

A Python CLI Expense Tracker built using Core Python to manage expenses with accumulators, input validation, and real-time total calculations.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages