forked from OpenBMB/ChatDev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
budget.py
30 lines (30 loc) · 1.3 KB
/
budget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'''
This file contains the Budget class which handles income, expense tracking, and reporting.
'''
class Budget:
def __init__(self):
self.income = []
self.expenses = []
def add_income(self, amount, description):
# Add income to the list
self.income.append({"amount": amount, "description": description})
def add_expense(self, amount, description):
# Add expense to the list
self.expenses.append({"amount": amount, "description": description})
def calculate_total_income(self):
# Calculate the total income
total_income = sum(income["amount"] for income in self.income)
return total_income
def calculate_total_expenses(self):
# Calculate the total expenses
total_expenses = sum(expense["amount"] for expense in self.expenses)
return total_expenses
def generate_report(self):
# Generate a report with income, expenses, and analytics
total_income = self.calculate_total_income()
total_expenses = self.calculate_total_expenses()
net_income = total_income - total_expenses if total_expenses else total_income
report = f"Total Income: ${total_income}\n"
report += f"Total Expenses: ${total_expenses}\n"
report += f"Net Income: ${net_income}\n"
return report