-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimple_expense_tracker.py
More file actions
36 lines (31 loc) · 897 Bytes
/
Simple_expense_tracker.py
File metadata and controls
36 lines (31 loc) · 897 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
def get_input():
cat = input("Enter category (Food, Transport, Entertainment, etc.): ").title()
amt = float(input("Enter expense amount: "))
return cat, amt
def add_expenses(exp, cat, amt):
if cat not in exp:
exp[cat] = []
exp[cat].append(amt)
def show_all(exp):
print("\n--- All Expenses by Category ---")
for cat in exp:
print(f"{cat}: {exp[cat]}")
def show_totals(exp):
print("\n--- Total Expenses by Category ---")
total = 0
for cat in exp:
cat_total = sum(exp[cat])
print(f"{cat}: {cat_total}")
total += cat_total
print(f"\nTotal: {total}")
def main():
exp = {}
while True:
cat, amt = get_input()
add_expenses(exp, cat, amt)
more = input("Add another expense? (yes/no): ").lower()
if more != "yes":
break
show_all(exp)
show_totals(exp)
main()