-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpense_tracker.py
More file actions
61 lines (40 loc) · 1.29 KB
/
Copy pathexpense_tracker.py
File metadata and controls
61 lines (40 loc) · 1.29 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Expense Tracker using Dictionary and File Handling
expenses = {}
while True:
print("\n===== Expense Tracker =====")
print("1. Add Expense")
print("2. View Expenses")
print("3. Total Expense")
print("4. Save to File")
print("5. Exit")
choice = input("Enter Choice: ")
if choice == "1":
category = input("Category: ")
amount = float(input("Amount: "))
if category in expenses:
expenses[category] += amount
else:
expenses[category] = amount
print("Expense Added Successfully!")
elif choice == "2":
print("\nExpense Summary:")
if len(expenses) == 0:
print("No Expenses Found")
else:
for category, amount in expenses.items():
print(f"{category}: ₹{amount}")
elif choice == "3":
total = sum(expenses.values())
print(f"\nTotal Expense = ₹{total}")
elif choice == "4":
with open("expenses.txt", "w") as file:
for category, amount in expenses.items():
file.write(
f"{category}: ₹{amount}\n"
)
print("Expenses Saved Successfully!")
elif choice == "5":
print("Thank You!")
break
else:
print("Invalid Choice")