-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpense_tracker.py
More file actions
45 lines (39 loc) · 1.28 KB
/
Copy pathexpense_tracker.py
File metadata and controls
45 lines (39 loc) · 1.28 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
print("Welcome to Expense Tracker")
expenses = []
while True:
print("\n===== Expense Tracker =====")
print("1. Add Expense")
print("2. View Expenses")
print("3. Total Expense")
print("4. Exit")
choice = input("Enter choice: ")
if choice == "1":
item = input("Enter expense name: ")
amount = float(input("Enter amount: "))
expenses.append([item, amount])
with open("expenses.txt", "a") as file:
file.write(f"{item},{amount}\n")
print("Expense Saved")
elif choice == "2":
try:
with open("expenses.txt", "r") as file:
for line in file:
item, amount = line.strip().split(",")
print(item, "-", amount)
except FileNotFoundError:
print("No Expenses Found")
elif choice == "3":
total = 0
try:
with open("expenses.txt", "r") as file:
for line in file:
item, amount = line.strip().split(",")
total += float(amount)
print("Total Expense =", total)
except FileNotFoundError:
print("No Expenses Found")
elif choice == "4":
print("Goodbye")
break
else:
print("Invalid Choice")