-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpense_tracker.py
More file actions
45 lines (32 loc) · 946 Bytes
/
Copy pathexpense_tracker.py
File metadata and controls
45 lines (32 loc) · 946 Bytes
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
import csv
def add_expense():
amount = input("Enter expense amount: ")
category = input("Enter category: ")
with open("expenses.csv", "a", newline="") as file:
writer = csv.writer(file)
writer.writerow([amount, category])
print("Expense added successfully!")
def view_expenses():
try:
with open("expenses.csv", "r") as file:
reader = csv.reader(file)
print("\nExpenses:")
for row in reader:
print(row)
except FileNotFoundError:
print("No expenses found!")
while True:
print("\n===== Expense Tracker =====")
print("1. Add Expense")
print("2. View Expenses")
print("3. Exit")
choice = input("Choose option: ")
if choice == "1":
add_expense()
elif choice == "2":
view_expenses()
elif choice == "3":
print("Goodbye!")
break
else:
print("Invalid Choice")