Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

💰 Expense Tracker

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.


Features

  • 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

Requirements

Requirement Version
Python 3.9 or higher
Dependencies None (standard library only)

Installation

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-tracker

Usage

python3 expense_tracker.py

Entering expenses

Type any positive number and press Enter:

  Enter expense amount: 49.99
  ✔  Added  : $49.99
     Total  : $49.99  (1 expense(s) so far)

Exiting the program

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

Sample Session

========================================
        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 Validation Rules

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().


Code Structure

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.


Design Decisions

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.


Known Limitations

  • 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.

License

MIT — free to use, modify, and distribute.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages