-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path57. Simple Expense Tracker.py
More file actions
38 lines (33 loc) · 1.05 KB
/
57. Simple Expense Tracker.py
File metadata and controls
38 lines (33 loc) · 1.05 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
class ExpenseTracker:
def __init__(self):
self.expenses = []
def add_expense(self, category, amount):
self.expenses.append((category, amount))
print("Expense added successfully!")
def view_expenses(self):
if self.expenses:
print("Expenses:")
for category, amount in self.expenses:
print(f"{category}: ${amount}")
else:
print("No expenses found.")
def main():
tracker = ExpenseTracker()
while True:
print("\n1. Add Expense")
print("2. View Expenses")
print("3. Exit")
choice = input("Enter your choice: ")
if choice == '1':
category = input("Enter expense category: ")
amount = float(input("Enter expense amount: "))
tracker.add_expense(category, amount)
elif choice == '2':
tracker.view_expenses()
elif choice == '3':
print("Exiting...")
break
else:
print("Invalid choice")
if __name__ == "__main__":
main()