0% found this document useful (0 votes)
6 views3 pages

Computer Project Latest - Removed

The document contains a Python script that reads and analyzes expense data from a CSV file. It processes transactions, categorizing expenses and summing amounts by category. If the file is not found or contains no entries, appropriate messages are displayed.

Uploaded by

Lakshmi.P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Computer Project Latest - Removed

The document contains a Python script that reads and analyzes expense data from a CSV file. It processes transactions, categorizing expenses and summing amounts by category. If the file is not found or contains no entries, appropriate messages are displayed.

Uploaded by

Lakshmi.P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

print("Date:",row[0], "\nType:",row[1],

"\nAmount:",row[2],"\nCategory:",row[3], "\
nDescription:",row[4]) print("\n") except
FileNotFoundError:
print("No entries yet. File not found.\n")

# Function to analyze expenses


def analyze_expenses():
# Dictionary to store category-wise spending
categories = {}

try:
# Read the file and analyze the expenses
with open('expenses.csv', 'r') as file:
reader = csv.reader(file)
rows = list(reader)

if len(rows) == 0:
print("No entries yet.\
n") else: for row
in rows:
transaction_type = row[1].lower() # Make the type case-
insensitive if transaction_type == "expense": # Only process
expenses category = row[3] amount =
float(row[2]) if category in categories:
categories[category] += amount
else:
categories[category] = amount

if len(categories) == 0:

You might also like