0% found this document useful (0 votes)
9 views1 page

Ndjdjurur

The ExpenseTracker class allows users to manage their expenses by adding them with a specified amount and category. It provides functionality to calculate total expenses and summarize expenses by category. The program runs in a loop, prompting the user to add expenses, view totals, or exit.

Uploaded by

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

Ndjdjurur

The ExpenseTracker class allows users to manage their expenses by adding them with a specified amount and category. It provides functionality to calculate total expenses and summarize expenses by category. The program runs in a loop, prompting the user to add expenses, view totals, or exit.

Uploaded by

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

class ExpenseTracker:

def __init__(self):
self.expenses = []

def add_expense(self, amount, category):


self.expenses.append({"amount": amount, "category": category})
print(f"Added expense: ₹{amount} in category '{category}'.")

def total_expenses(self):
total = sum(expense["amount"] for expense in self.expenses)
print(f"---Total Expenses: ₹{total}---")

def category_summary(self):
summary = {}
for expense in self.expenses:
category = expense["category"]
summary[category] = summary.get(category, 0) + expense["amount"]

print("------Expense Summary by -e/ndjdjurur-----")


for category, amount in summary.items():
print(f"{category}: ₹{amount}")

if __name__ == "__main__":
tracker = ExpenseTracker()
print("---e/ndjdjurur welcomes you to the expensetracker---")

while True:
print("---e/ndjdjurur welcomes you to the expensetracker---")
print("\n1. Add Expense\n2. Show Total Expenses\n3. Show Category Summary\
n4. Exit")
choice = input("Enter your choice: ")

if choice == "1":
amount = float(input("Enter amount: "))
category = input("Enter category: ")
tracker.add_expense(amount, category)
elif choice == "2":
tracker.total_expenses()
elif choice == "3":
tracker.category_summary()
elif choice == "4":
print("Exiting Expense Tracker.")
break
else:
print("Invalid choice, please try again.")

You might also like