-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracker.py
More file actions
42 lines (32 loc) · 1.2 KB
/
Copy pathtracker.py
File metadata and controls
42 lines (32 loc) · 1.2 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
class ExpenseTracker:
def __init__(self):
self.balance = 0.0
self.expenses = []
def add_expense(self, amount, category, description):
self.expenses.append({
'amount': amount,
'category': category,
'description': description
})
self.balance -= amount
def income(self, amount):
self.balance += amount
def view_expenses(self):
print("Expense List:")
for expense in self.expenses:
print(f"Amount: Rs.{expense['amount']}, Category: {expense['category']}, Description: {expense['description']}")
def current_balance(self):
print(f"Your current balance is Rs.{self.balance:.2f}")
# Example usage:
tracker = ExpenseTracker()
# Adding expenses
tracker.add_expense(50.0, 'Food', 'Lunch and Dinner everyday')
tracker.add_expense(20.0, 'Transport', 'Taxi')
tracker.add_expense(40.0, 'Entertainment', 'TV')
tracker.add_expense(20.0, 'Grocery', 'Everyday home need such as vegetables,bakery etc')
tracker.add_expense(30.0, 'Light Bill', 'Fan and Electricity used everyday')
# Adding income
tracker.income(1000.0)
# Viewing expenses and balance
tracker.view_expenses()
tracker.current_balance()