Skip to content

I am Building a Personal Expense Tracker Real World Practice Project 1 for Practicing my Skills

Notifications You must be signed in to change notification settings

LakshyaPandey3/RealWorldPracticeProject1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

RealWorldPracticeProject1

I am Building a Personal Expense Tracker Real World Practice Project 1 for Practicing my Skills

💰 Personal Expense Tracker CLI

A comprehensive command-line application for managing and tracking your daily expenses with ease.

Python Version

🎯 Overview

Personal Expense Tracker CLI is a lightweight, user-friendly command-line application designed to help you efficiently manage your daily expenses. Whether you're tracking personal spending, managing a budget, or analyzing your financial habits, this application provides a simple yet powerful solution.

Built with Python, this project demonstrates core programming concepts including:

  • Data structures (Lists and Dictionaries)
  • Control flow and loops
  • User input handling
  • CRUD operations (Create, Read, Update, Delete)

✨ Features

Core Functionality

  • Add Expenses - Quickly log new expenses with date, category, description, and amount
  • View All Expenses - Display all recorded expenses in an organized format
  • Update Expenses - Modify existing expense details with flexible field updates
  • Delete Expenses - Remove unwanted expenses from your records
  • Total Expenses Count - Get a quick count of how many expenses you've tracked
  • Total Amount Calculation - Automatically calculate and display your total spending

User Experience

  • 🎨 Clean and intuitive menu-driven interface
  • 💻 Interactive command-line interaction
  • ✔️ Input validation and error handling
  • 📊 Organized expense display with clear formatting
  • 🔄 Real-time expense list updates

📦 System Requirements

  • Python: 3.7 or higher
  • Operating System: Windows, macOS, or Linux
  • Terminal/Console: Any standard command-line interface
  • Storage: Minimal (in-memory storage during session)

🔍 Features in Detail

  1. Add a Expense (Option 1) Allows you to create a new expense entry with the following details:

Date: The date when the expense occurred (e.g., 2025-02-17) Category: Type of expense (e.g., Food, Transport, Entertainment, Bills) Description: Detailed description of the expense Amount: The expense amount in your preferred currency Example Input:

Code Enter the Date of Expense : 2025-02-17 Enter the Category of the Expense : Food Enter the Details of the Expense : Lunch at Restaurant Enter the Amount of the Expense : 500 2. View Expenses (Option 2) Displays all recorded expenses in a formatted list:

Code ========THESE ARE YOUR EXPENSES======== 1: 2025-02-17 , Food , Lunch at Restaurant , 500 2: 2025-02-16 , Transport , Taxi Fare , 250 3: 2025-02-15 , Entertainment , Movie Tickets , 800 3. Update Expenses (Option 3) Modify any existing expense entry:

Select the expense number to update Enter the new details (leave blank to keep existing values) View the updated expense list Example:

Code ========UPDATE EXPENSES======== 1: 2025-02-17 , Food , Lunch at Restaurant , 500 Enter the expense number to update: 1

Enter new details: New Date : 2025-02-18 New Category : Food New Description : Dinner at Restaurant New amount : 600 4. Delete Expenses (Option 4) Remove an expense from your records:

View all expenses Select the expense number to delete Confirmation of deletion 5. Total Number of Expenses (Option 5) Get a quick count of all recorded expenses:

Code The total number of Expenses you have done are: 5 6. Total Amount of Expenses (Option 6) Calculate and display your total spending:

Code ========TOTAL EXPENSE AMOUNT======= Total Amount Spent: 2050 7. Exit (Option 7) Safely close the application with a thank you message

📸 Screenshots Welcome Screen Code Welcome to the Personal Expense Tracker CLI Application: ========MENU========

  1. Add a Expense
  2. View Expenses
  3. Update Expenses
  4. Delete Expenses
  5. Total Number of Expenses
  6. Total Amount of Expenses
  7. Exit Enter your choice: Sample Expense View Code ========THESE ARE YOUR EXPENSES======== 1: 2025-02-17 , Food , Lunch at Restaurant , 500 2: 2025-02-16 , Transport , Taxi Fare , 250 3: 2025-02-15 , Entertainment , Movie Tickets , 800 💡 How to Use Examples Example Workflow: Daily Expense Tracking Step 1: Start the Application

bash python PersonalExpenceTrackerpracticeproject-1_CLI.py Step 2: Add Your First Expense

Code Enter your choice: 1 Enter the Date of Expense : 2025-02-17 Enter the Category of the Expense : Groceries Enter the Details of the Expense : Weekly grocery shopping Enter the Amount of the Expense : 1200

The Expense is successfully added to the Expenses List Step 3: Add More Expenses

Repeat for additional expenses (lunch, transport, utilities, etc.) Step 4: View All Expenses

Code Enter your choice: 2 Step 5: Check Total Spending

Code Enter your choice: 6 Total Amount Spent: 2050 Step 6: Update if Needed

Code Enter your choice: 3 Step 7: Exit the Application

Code Enter your choice: 7 Thankyou for using this Expense Tracking Application Exiting the program................

Copilot said: I'll provide you with an extremely detailed I'll provide you with an extremely detailed explanation of every single line and word in your code. Let me break it down into sections:

🔍 COMPLETE CODE BREAKDOWN - LINE BY LINE

Section 1: Initial Setup & Comment Python

Real World Project Practice Personal expense tracker CLI Project

Explanation:

- This is a comment symbol in Python

Everything after # on the same line is a comment (not executed code) Comments are used to document code and explain what the program does Purpose: This particular comment explains that this is a real-world practice project for building a Personal Expense Tracker with a Command-Line Interface (CLI)

Section 2: Initialize Empty List Python expensesList = [] Detailed Breakdown:

Component What It Does Details expensesList Variable Name This is an identifier that stores data. The name is descriptive - it tells us it will contain a list of expenses. Using camelCase (first word lowercase, subsequent words capitalized) follows Python naming conventions. = Assignment Operator This operator assigns the value on the right side to the variable on the left. It means "store this value in this variable" [] Empty List Literal Square brackets in Python represent a list - a container that can hold multiple items. The empty brackets [] mean this list starts with zero items. Lists are ordered, mutable (changeable), and allow duplicate values. What happens:

Memory is allocated for a variable called expensesList It's initialized as an empty list that can later store expense dictionaries This list will grow as users add expenses to the application Example of what it will contain later:

Python expensesList = [ {"Date": "2025-02-17", "Category": "Food", "Description": "Lunch", "Amount": "500"}, {"Date": "2025-02-16", "Category": "Transport", "Description": "Taxi", "Amount": "250"} ]

Section 3: Welcome Message Python print("Welcome to the Personal Expense Tracker CLI Application: ") Detailed Breakdown:

Component Explanation print() Built-in function - Outputs text to the console/terminal. It automatically adds a newline at the end. print is a fundamental Python function for displaying information to users. ( ) Parentheses - Function arguments are placed inside parentheses. In Python 3, print() requires parentheses (unlike Python 2 where it was print without parentheses). "Welcome to the Personal Expense Tracker CLI Application: " String literal - Text enclosed in double quotes. A string is a sequence of characters. This specific string is the welcome message shown to users when they first run the program. What happens:

The print() function takes the string as an argument It displays exactly: Welcome to the Personal Expense Tracker CLI Application: A newline is automatically added, so the cursor moves to the next line

Section 4: Main Loop - Outer Structure Python while True: Detailed Breakdown:

Component Explanation while Loop keyword - Creates a "while loop" that repeats code as long as a condition is true. The code block indented under while will execute repeatedly. True Boolean constant - One of two boolean values in Python (True or False). True means the condition is always true. : Colon - Indicates the start of a code block. Python uses colons to denote the beginning of indented blocks (like loops, functions, conditionals). Purpose:

while True: creates an infinite loop that continues until explicitly broken (using break statement) This is the main control loop of the application The program will keep showing the menu and processing user choices until the user selects "Exit" Flow:

Loop starts Menu is displayed User makes a choice Choice is processed Loop returns to step 2 (unless user exits) Loop continues until break is executed

Section 5: Menu Display Python print("========MENU========") print("1. Add a Expense ") print("2. View Expenses ") print("3. Update Expenses ") print("4. Delete Expenses ") print("5. Total Number of Expenses ") print("6. Total Amount of Expenses ") print("7. Exit ") Detailed Breakdown:

Line What It Does print("========MENU========") Prints a header line with equal signs to visually separate the menu. Creates a border-like effect. ======== is just repeated equals signs for decoration. print("1. Add a Expense ") Displays menu option 1. The number 1 is the choice the user must enter to select this option. print("2. View Expenses ") Displays menu option 2. Same pattern repeated. print("3. Update Expenses ") Displays menu option 3. print("4. Delete Expenses ") Displays menu option 4. print("5. Total Number of Expenses ") Displays menu option 5. print("6. Total Amount of Expenses ") Displays menu option 6. print("7. Exit ") Displays menu option 7. Selecting this will exit the program. Indentation:

All these print() statements are indented with 4 spaces This indentation means they're part of the while True: block They'll execute every time the loop runs In Python, indentation is mandatory and defines code blocks Visual Output:

Code ========MENU========

  1. Add a Expense
  2. View Expenses
  3. Update Expenses
  4. Delete Expenses
  5. Total Number of Expenses
  6. Total Amount of Expenses
  7. Exit

Section 6: Get User Choice Python choice = int(input("Enter your choice: ")) Detailed Breakdown:

Component Explanation Details choice Variable name Stores the user's menu selection. Will contain an integer from 1-7 (or any number the user enters). = Assignment operator Assigns the result of the right side to the choice variable. input() Built-in function Pauses the program and waits for user input from the keyboard. Returns the input as a STRING regardless of what the user types. "Enter your choice: " String argument This is the prompt displayed to the user. It tells them what to do. int() Type conversion function Converts the string input into an integer (whole number). For example, converts "5" (string) to 5 (integer). Execution Flow:

input("Enter your choice: ") displays the prompt: Enter your choice: Program waits for the user to type something and press Enter The user types a number (e.g., 3) and presses Enter input() returns this as a string: "3" int() converts it to an integer: 3 The integer 3 is stored in the variable choice Why int() is needed:

input() always returns a string, even if user types numbers Menu logic needs to compare numbers, so we convert to int This allows us to do if choice == 1: instead of if choice == "1": Potential Issue:

If the user enters non-numeric input, int() will raise an error The code doesn't handle this error (no try-except block) This is a limitation of the program

Section 7: Choice 1 - Add Expense Python if choice == 1: Detailed Breakdown:

Component Explanation if Conditional keyword - Checks if a condition is true. If true, the indented block executes. If false, the next elif or else is checked. choice Variable - Contains the user's menu choice (converted to integer). == Comparison operator - Means "is equal to". Checks if two values are identical. Different from = (assignment). 1 Integer literal - The number 1. Checks if choice equals exactly 1. : Colon - Starts the code block for this condition. Logic:

If the user entered 1 (chose "Add a Expense"), this block executes All the code indented under this if statement is part of this block If user chose something else (2, 3, 4, etc.), this block is skipped

Section 8: Input Fields for Adding Expense Python date = input("Enter the Date of Expense : ") category = input("Enter the Category of the Expense : ") description = input("Enter the Details of the Expense : ") amount = input("Enter the Amount of the Expense : ") Detailed Breakdown:

Each line follows the same pattern:

Line Variable Prompt Purpose date = input("...") date "Enter the Date of Expense : " Stores the expense date (e.g., "2025-02-17") category = input("...") category "Enter the Category of the Expense : " Stores the expense category (e.g., "Food") description = input("...") description "Enter the Details of the Expense : " Stores detailed description (e.g., "Lunch at restaurant") amount = input("...") amount "Enter the Amount of the Expense : " Stores the amount as a STRING (e.g., "500") Key Points:

Each input() call pauses and waits for user input The value is stored in the corresponding variable All values are stored as STRINGS (even the amount) These variables are temporary, only exist within this code block Example User Interaction:

Code Enter the Date of Expense : 2025-02-17 Enter the Category of the Expense : Food Enter the Details of the Expense : Lunch at restaurant Enter the Amount of the Expense : 500 After this:

date = "2025-02-17" category = "Food" description = "Lunch at restaurant" amount = "500"

Section 9: Create Expense Dictionary Python expense = { "Date": date, "Category": category, "Description": description, "Amount": amount } Detailed Breakdown:

Component Explanation expense Variable name - Will store a dictionary containing one expense record. = Assignment operator - Assigns the dictionary to the variable. {} Dictionary literal - Curly braces denote a dictionary in Python. Dictionaries store key-value pairs. "Date" String key - The key is a descriptive label. Keys are always strings in this case. : Colon - Separates key from value in a dictionary. date Variable reference - The value being stored (without quotes, so it's the variable value, not the string "date"). Full Structure:

Python expense = { "Date": date, # Key: "Date", Value: the date variable "Category": category, # Key: "Category", Value: the category variable "Description": description, # Key: "Description", Value: the description variable "Amount": amount # Key: "Amount", Value: the amount variable } What this creates: A dictionary with 4 key-value pairs. If the user entered:

Date: 2025-02-17 Category: Food Description: Lunch Amount: 500 The dictionary would look like:

Python { "Date": "2025-02-17", "Category": "Food", "Description": "Lunch", "Amount": "500" } Why use dictionaries?

Keeps related data grouped together Can access values by key: expense["Date"] returns "2025-02-17" More readable than storing as separate variables Makes it easy to add to the list later

Section 10: Add to List Python expensesList.append(expense) Detailed Breakdown:

Component Explanation expensesList List variable - The main list storing all expenses. . Dot operator - Accesses methods and attributes of an object. Here, accesses the append method. append() List method - Adds a single item to the end of a list. Always adds to the last position. expense Argument - The dictionary created above that should be added to the list. What happens:

The append() method takes the expense dictionary Adds it as the last element of expensesList The list grows by one item Example:

Python

Before

expensesList = []

After first append

expensesList = [ {"Date": "2025-02-17", "Category": "Food", "Description": "Lunch", "Amount": "500"} ]

After second append

expensesList = [ {"Date": "2025-02-17", "Category": "Food", "Description": "Lunch", "Amount": "500"}, {"Date": "2025-02-16", "Category": "Transport", "Description": "Taxi", "Amount": "250"} ] Different from extend():

Python append() # Adds single item (list grows by 1) extend() # Adds multiple items (list grows by multiple)

Section 11: Confirmation Message Python print("\n The Expense is successfully added to the Expenses List ") Detailed Breakdown:

Component Explanation print() Built-in function - Displays output. "\n..." String with escape sequence - \n is a newline character. Moves cursor to next line before printing the text. The Expense is... Text message - User feedback confirming the expense was added successfully. What displays:

Code (empty line) The Expense is successfully added to the Expenses List The \n at the beginning adds a blank line before the message, improving readability.

Section 12: Choice 2 - View Expenses Python elif choice == 2: Detailed Breakdown:

Component Explanation elif Else-if keyword - Checked only if the previous if was false. Allows multiple conditions in sequence. choice == 2 Condition - Checks if user chose option 2 (View Expenses). Flow:

If if choice == 1: was true, this elif is skipped Only checked if choice is NOT 1 If choice IS 2, this block executes Otherwise, continues to the next elif

Section 13: Check if List is Empty Python if len(expensesList)==0: Detailed Breakdown:

Component Explanation if Conditional keyword - Checks if a condition is true. len() Built-in function - Returns the LENGTH (number of items) in a list. expensesList List variable - The list we're checking. ==0 Comparison - Checks if the length equals 0 (meaning the list is empty). Logic:

Python len(expensesList) # Returns the count of items len([]) # Returns 0 len([item1, item2]) # Returns 2 Purpose:

Can't view expenses if the list is empty This checks for that condition If true (list is empty), display a message If false (list has items), display all items

Section 14: Empty List Message Python print("\n The Expenses List is empty ") Explanation:

Displays if the list has no expenses The \n adds a blank line before the message Tells the user there are no expenses to view

Section 15: Else Block for Viewing Python else: Explanation:

else - Executed if the if condition above was false Means: if the list is NOT empty, execute this block This is where all expenses are displayed

Section 16: Display Expenses Header Python print("========THESE ARE YOUR EXPENSES========") Explanation:

Prints a header to visually separate the expense list Makes the output more organized and readable

Section 17: Initialize Counter Python count = 1 Detailed Breakdown:

Component Explanation count Variable name - Will keep track of the expense number in the display. = Assignment operator - Sets initial value. 1 Integer literal - Starts counting from 1 (not 0, because users prefer 1-based numbering). Purpose:

Display expenses as "1: ...", "2: ...", "3: ...", etc. Helps users identify which expense number to select for update/delete

Section 18: Loop Through Expenses Python for expense in expensesList: Detailed Breakdown:

Component Explanation for Loop keyword - Iterates through items in a sequence. expense Loop variable - Each iteration, expense becomes the current item from the list. in Membership keyword - Means "from" or "in". Specifies the sequence to iterate through. expensesList List being iterated - The loop goes through each dictionary in this list one by one. : Colon - Starts the code block for this loop. How it works:

Python

First iteration: expense = {"Date": "2025-02-17", "Category": "Food", ...}

Second iteration: expense = {"Date": "2025-02-16", "Category": "Transport", ...}

Third iteration: expense = {"Date": "2025-02-15", "Category": "Entertainment", ...}

etc.

Versus while loop:

for loop is cleaner when you know you want to iterate through every item while loop requires manual counter management In this case, for is the best choice

Section 19: Print Each Expense Python print(f" {count}: {expense["Date"]} , {expense["Category"]} , {expense["Description"]} , {expense["Amount"]} ") Detailed Breakdown:

Component Explanation print() Built-in function - Displays the expense. f"..." F-string (formatted string literal) - Allows embedding variables directly in strings using curly braces {}. The f prefix tells Python to interpret the braces as code, not text. {count} Variable interpolation - Replaced with the current value of count. If count is 1, displays 1. : Text - Literal colon character that separates the number from the data. {expense["Date"]} Dictionary access via f-string - Accesses the "Date" key from the current expense dictionary. Displays the date value. , Text - Literal comma with spaces. Used to separate the fields for readability. {expense["Category"]} Dictionary access - Gets the category from the expense. More commas and fields Same pattern - Description and Amount are accessed the same way. Example Output:

Code 1: 2025-02-17 , Food , Lunch at Restaurant , 500 2: 2025-02-16 , Transport , Taxi Fare , 250 3: 2025-02-15 , Entertainment , Movie Tickets , 800 F-string alternative (older syntax):

Python

Old way (not used in this code)

print(" {}: {} , {} , {} , {} ".format(count, expense["Date"], expense["Category"], expense["Description"], expense["Amount"]))

F-string (modern, used in code)

print(f" {count}: {expense["Date"]} , {expense["Category"]} , {expense["Description"]} , {expense["Amount"]} ") F-strings are more readable and were introduced in Python 3.6+.

Section 20: Increment Counter Python count += 1 Detailed Breakdown:

Component Explanation count Variable - The counter we initialized at 1. += Compound assignment operator - Shorthand for count = count + 1. Adds 1 to the current value. 1 Integer literal - The amount to add. Equivalent operations:

Python count += 1 # Shorthand (what the code uses) count = count + 1 # Explicit assignment (same result) count++ # Doesn't work in Python (works in other languages) Purpose:

Each iteration increments count by 1 First expense shows as "1: ..." Second shows as "2: ..." Third shows as "3: ..." And so on...

Section 21: Choice 3 - Update Expenses Python elif choice == 3: Explanation:

If user entered choice 3, enter the update expenses block Follows the same pattern as previous elif statements

Section 22: Check if List is Empty (for Update) Python if len(expensesList)==0: print("\n The expenses list is empty ") else: print("========UPDATE EXPENSES========") Explanation:

Same logic as viewing: check if list is empty If empty, tell user If not empty, show the UPDATE EXPENSES header Then proceed with update logic

Section 23: Loop to Display Expenses for Update Python for i, expense in enumerate(expensesList, start=1): Detailed Breakdown:

Component Explanation for Loop keyword - Iterates through the list. i Loop variable - Will be the INDEX (position) of each item. , Comma - Separates multiple loop variables. expense Loop variable - Will be the actual dictionary (the item itself). in Membership keyword - From the sequence. enumerate() Built-in function - Provides both INDEX and VALUE for each item. Without enumerate(), you only get the value. expensesList The list being enumerated. start=1 Parameter - Makes enumeration start at 1 instead of 0. Means first index is 1, second is 2, etc. Comparison with regular for loop:

Python

Regular for loop - only get expense

for expense in expensesList: # Don't know the index/position

enumerate() - get both index and expense

for i, expense in enumerate(expensesList, start=1): # i is the position (1, 2, 3, ...) # expense is the dictionary Example:

Python

First iteration: i = 1, expense = {...}

Second iteration: i = 2, expense = {...}

Third iteration: i = 3, expense = {...}

Why start=1?

By default, enumerate starts at 0 (0, 1, 2, ...) Users prefer 1-based numbering (1, 2, 3, ...) start=1 adjusts this

Section 24: Display Expense for Updating Python print(f"{i}: {expense["Date"]} , {expense["Category"]} , {expense["Description"]} , {expense["Amount"]} ") Explanation:

Same as the display we saw before Shows each expense with its number Uses f-string to embed variables User sees which number corresponds to which expense

Section 25: Get Expense to Update Python update_index = int(input("Enter the expense number to update: ")) - 1 Detailed Breakdown:

Component Explanation update_index Variable - Will store the actual list index to update. int(input(...)) Get user input and convert to integer - User enters a number like 1, 2, 3, etc. " Enter the expense number to update: " Prompt - Asks which expense to update.

  • 1 Subtract 1 - CRUCIAL! Converts user's 1-based numbering to 0-based list indexing. Why subtract 1?

Users see expenses numbered 1, 2, 3 But lists are indexed 0, 1, 2 If user enters 1, we need to access index 0 Formula: list_index = user_number - 1 Example:

Python

User sees "1: ..." and enters 1

update_index = int(input()) - 1

= 1 - 1 = 0 (correct list index)

User sees "3: ..." and enters 3

update_index = int(input()) - 1

= 3 - 1 = 2 (correct list index)

Section 26: Validate Index Python if 0 <= update_index < len(expensesList): Detailed Breakdown:

Component Explanation

if Conditional keyword - Check a condition. 0 <= update_index < len(expensesList) Comparison chain - Checks TWO conditions at once. 0 <= At least 0 - Index cannot be negative. update_index The index entered by user. < Less than - Second comparison operator. len(expensesList) List length - Index must be less than the list length. What this validates:

Index must be >= 0 (not negative) Index must be < length of list (not out of bounds) Only valid indices pass this check Example:

Python expensesList = [item1, item2, item3] # 3 items len(expensesList) = 3

Valid indices: 0, 1, 2

0 <= 0 < 3 # True ✓ 0 <= 1 < 3 # True ✓ 0 <= 2 < 3 # True ✓

Invalid indices:

0 <= -1 < 3 # False (negative) ✗ 0 <= 3 < 3 # False (too large) ✗ 0 <= 100 < 3 # False (way too large) ✗

Section 27: Get New Details Python print("\nEnter new details : ")

                new_date = input("New Date : ")
                new_category = input("New Category : ")
                new_description = input("New Description : ")
                new_amount = input("New amount : ")

Explanation:

Shows header message Gets four new inputs for the expense fields Stored in separate variables: new_date, new_category, etc. User can provide new values for any field These are separate from the original values Section 28: Conditional Update (Only if Not Empty) Python if new_date: expensesList[update_index]["Date"] = new_date Detailed Breakdown:

Component Explanation

if new_date: Check if not empty - In Python, non-empty strings are "truthy". If user entered something, the string is not empty, condition is true. expensesList[update_index] Access specific expense - Gets the dictionary at that index. ["Date"] Access dictionary key - Gets the "Date" value from that dictionary. = Assignment - Replaces the old value with the new value. new_date New value - The new date entered by user. Key Feature:

Only updates if user entered a value If user pressed Enter without typing (empty input), the condition is false Old value is preserved Allows partial updates (update only the fields you want to change) Flow:

Python

User can enter new values OR press Enter to skip

Example: If they only want to change the date

Enter new details: New Date : 2025-02-18 # User enters new date New Category : # User presses Enter (empty) New Description : # User presses Enter (empty) New amount : 600 # User enters new amount

Result: Only Date and Amount are updated

Category and Description remain unchanged

Repeated for other fields:

Python if new_category: expensesList[update_index]["Category"] = new_category

if new_description: expensesList[update_index]["Description"] = new_description

if new_amount: expensesList[update_index]["Amount"] = new_amount

Section 29: Confirmation & Display Updated List Python print("\n The Expenses List is successfully updated ")

                print("\n========UPDATED EXPENSE LIST========")

                for index, expense in enumerate(expensesList, start=1):
                    print(f"{index} : {expense['Date']} | {expense['Category']} | {expense['Description']} | {expense['Amount']} ")

Explanation:

First print: Confirmation message Second print: Header for updated list Loop: Displays all expenses again Using enumerate() with start=1 to number from 1 Uses | (pipe) to separate fields (different from the , used before) Shows user the updated list to confirm changes

Section 30: Invalid Index Else Python else: print("\n Invalid expense number ") Explanation:

If the index validation failed (index was out of range) Tell user the number they entered was invalid No update occurs Section 31: Choice 4 - Delete Expenses Python elif choice == 4: Explanation:

Enters delete expenses block if user chose option 4

Section 32: Check if List is Empty (for Delete) Python if len(expensesList) == 0: print("\n The Expenses List is empty ")

    else:
        print("========DELETE EXPENSES========")

Explanation:

Same pattern as view and update Check if list is empty Can't delete if there's nothing Otherwise, show DELETE header and proceed

Section 33: Display Expenses for Deletion Python for i, expense in enumerate(expensesList, start=1): print(f"{i}: {expense["Date"]} , {expense["Category"]} , {expense["Description"]} , {expense["Amount"]} ") Explanation:

Same as before: loop through and display each expense Shows numbering so user can identify which to delete

Section 34: Get Expense to Delete Python delete_index = int(input("Enter the expense number to delete: ")) - 1 Explanation:

Same as update: get user input and convert to list index Subtract 1 to convert from 1-based to 0-based indexing

Section 35: Validate and Delete Python if 0 <= delete_index < len(expensesList): deleted_expense = expensesList.pop(delete_index) print("\n The Expense is successfully deleted ") Detailed Breakdown:

Component Explanation if 0 <= delete_index < len(expensesList): Validate index - Same validation as update. deleted_expense = expensesList.pop(delete_index) Remove and store - pop() removes the item at that index AND returns it. We store it in deleted_expense (though we don't actually use it later). expensesList.pop(delete_index) List method: pop() - Removes and returns the item at the index. Different from remove() which searches for value. print("\n The Expense is successfully deleted ") Confirmation - Tell user deletion was successful. pop() vs remove():

Python

pop() - remove by index

expensesList.pop(0) # Removes first item

remove() - remove by value

expensesList.remove({"Date": "2025-02-17", ...}) # Removes matching item

Section 36: Check if List is Empty After Delete Python if len(expensesList) == 0: print("\n The Expense List is empty now ") Explanation:

After deletion, check if there are any expenses left If not, tell the user the list is now empty

Section 37: Display Updated List After Delete Python else: print("========UPDATED EXPENSES LIST========") for index, expense in enumerate(expensesList, start=1): print(f"{index} : {expense['Date']} | {expense['Category']} | {expense['Description']} | {expense['Amount']} ") Explanation:

If list is not empty after deletion Show the remaining expenses Uses single quotes ' instead of double quotes " (both work the same in Python) Uses | separator (pipe character) instead of ,

Section 38: Invalid Delete Index Python else: print("\n Invalid expense number ") Explanation:

If deletion index was invalid (out of range) Show error message No deletion occurs Section 39: Choice 5 - Total Count Python elif choice == 5:

    print(f"The total number of Expenses you have done are: {len(expensesList)}")

Detailed Breakdown:

Component Explanation elif choice == 5: Check if choice is 5 - User selected total count option. len(expensesList) Get list length - Returns the number of items (expenses). {len(expensesList)} F-string interpolation - Embeds the count in the message. Example Output:

Code The total number of Expenses you have done are: 5 Section 40: Choice 6 - Total Amount Python elif choice == 6:

    if len(expensesList) == 0:
        print("\n  The Expenses List is empty ")
    else:
        total_expenses = 0

        for expense in expensesList:
            total_expenses += int(expense["Amount"])

        print("========TOTAL EXPENSE AMOUNT=======")
        print(f"Total Amount Spent: {total_expenses}")

Detailed Breakdown:

Part Explanation elif choice == 6: Check if choice is 6 - User wants total amount. if len(expensesList) == 0: Check if empty - Can't calculate if no expenses. total_expenses = 0 Initialize accumulator - Variable to sum all amounts. Starts at 0. for expense in expensesList: Loop through each expense - Go through every expense dictionary. total_expenses += int(expense["Amount"]) Add to total - Extract the amount, convert to int, add to total. int(expense["Amount"]) Convert string to int - Amounts are stored as strings, need conversion for math. += Accumulate - Shorthand for total_expenses = total_expenses + int(...) print("========...") Header - Visual separator for the result. print(f"Total Amount Spent: {total_expenses}") Display result - Shows the calculated total.

How the calculation works:

Python

Example expenses

expensesList = [ {"Amount": "500"}, {"Amount": "250"}, {"Amount": "800"} ]

total_expenses = 0

First iteration

total_expenses += int("500") # = 0 + 500 = 500

Second iteration

total_expenses += int("250") # = 500 + 250 = 750

Third iteration

total_expenses += int("800") # = 750 + 800 = 1550

Result: 1550

Section 41: Choice 7 - Exit Python elif choice == 7: print("\n Thankyou for using this Expense Tracking Application") print(" Exiting the program................") break

Detailed Breakdown:

Component Explanation elif choice == 7: Check if choice is 7 - User selected exit. print(...) Thank you message - Polite goodbye message. print(...) Exit message - Shows program is closing. break Break keyword - EXITS THE LOOP. Stops the while True: loop, ending the program.

The break statement:

Only way to exit the while True: infinite loop When executed, jumps out of the loop Program terminates normally

Section 42: Invalid Choice Python else: print("\n Invalid choice ") Explanation:

If user entered a number that's not 1-7 Tell them the choice is invalid Loop continues, menu shows again User can try again

🎓 COMPREHENSIVE SUMMARY TABLE Here's a table summarizing the key concepts used:

Concept What It Is Used For while True: Infinite loop Main program loop until user exits if/elif/else Conditional execution Route to different code based on choice input() Get user input Read menu choice and expense data int() Type conversion Convert string input to number [] List literal Container for multiple expenses {} Dictionary literal Store related data (expense record) .append() List method Add expense to list .pop() List method Remove expense from list for loop Iterate through sequence Display each expense enumerate() Built-in function Get both index and value len() Built-in function Get count of items print() Built-in function Display output f"..." F-string Embed variables in text += Compound operator Add and assign break Control flow Exit loop == Comparison Check equality

🔑 KEY INSIGHTS

Data Structure: Uses a list of dictionaries - very common pattern in Python CRUD Operations: Demonstrates all four - Create (add), Read (view), Update, Delete User Input Handling: Gets input, converts types, validates ranges Loop Control: Uses while True with break to control execution Conditional Logic: Uses if/elif/else to route to different features String Formatting: Uses f-strings for clean output

This is an excellent beginner project for learning fundamental Python concepts!

About

I am Building a Personal Expense Tracker Real World Practice Project 1 for Practicing my Skills

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages