A simple, console-based Expense Tracking System implemented in Python. This project is designed to demonstrate fundamental programming concepts such as functions, lists, dictionaries, validation logic, exception handling, and code structure.
This system allows users to log expenses, categorize them, and retrieve summaries. The program maintains a global list of expenses and provides specific utility functions to analyze spending patterns.
- All expenses are stored in a global list named
expenses. - Each expense is represented as a dictionary with the following keys:
amount(float or int)category(string)description(string)
- Validation: Ensures the
amountis strictly greater than0. - Error Handling: Raises a
ValueErrorif the amount is invalid. - Storage: Creates the expense dictionary, appends it to the
expenseslist, and returns the newly created dictionary.
- Iterates through the
expenseslist. - Computes and returns the sum of all recorded expenses.
- Iterates through the
expenseslist. - Computes and returns the total sum for the specified category.
- Iterates through and prints all stored expenses in a clear, readable format.
A test block must be included at the bottom of the script to demonstrate the system's functionality. The test suite should perform the following actions:
- Add multiple valid expenses.
- Attempt to add at least one invalid expense (e.g., negative amount or zero) within a
try-exceptblock to verify exception handling. - Print the overall total expenses.
- Print the total expenses for a specific category.
- Display all stored expenses.
To ensure high-quality code, your implementation should meet the following standards:
- Clean & Structured Code: Follow standard Python formatting and indentation (PEP 8 guidelines).
- Readable Naming Conventions: Use descriptive variable and function names.
- Documentation: Include docstrings for each function explaining their purpose, parameters, and return types.
- Comments: Add concise comments where necessary to clarify logic.
- No Redundancy: Keep the code DRY (Don't Repeat Yourself).