MCPcopy Create free account
hub / github.com/geekcomputers/Python / add_expense

Function add_expense

Personal-Expense-Tracker/expense_tracker.py:4–17  ·  view source on GitHub ↗
(expenses)

Source from the content-addressed store, hash-verified

2
3
4def add_expense(expenses):
5 amount = float(input("Enter the expense amount: "))
6 category = input("Category (food, travel, shopping, bills, etc.): ")
7 date_str = input("Date (YYYY-MM-DD): ")
8 try:
9 date = datetime.datetime.strptime(date_str, "%Y-%m-%d").date()
10 except ValueError:
11 print("Incorrect date format. Please use YYYY-MM-DD format.")
12 return
13 note = input("(Optional) Note: ")
14 expenses.append(
15 {"amount": amount, "category": category, "date": date, "note": note}
16 )
17 print("Expense added!")
18
19
20def view_expenses(expenses, period="all", category_filter=None):

Callers 1

mainFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected