Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

Expense Tracking System

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.

Overview

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.


Features & Requirements

1. Data Structure

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

2. Functional Requirements

add_expense(amount, category, description)

  • Validation: Ensures the amount is strictly greater than 0.
  • Error Handling: Raises a ValueError if the amount is invalid.
  • Storage: Creates the expense dictionary, appends it to the expenses list, and returns the newly created dictionary.

calculate_total_expenses()

  • Iterates through the expenses list.
  • Computes and returns the sum of all recorded expenses.

calculate_total_by_category(category)

  • Iterates through the expenses list.
  • Computes and returns the total sum for the specified category.

show_expenses()

  • Iterates through and prints all stored expenses in a clear, readable format.

Testing Requirements

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:

  1. Add multiple valid expenses.
  2. Attempt to add at least one invalid expense (e.g., negative amount or zero) within a try-except block to verify exception handling.
  3. Print the overall total expenses.
  4. Print the total expenses for a specific category.
  5. Display all stored expenses.

Code Best Practices

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