Symptom
Calling generate_monthly_report() raises UnboundLocalError: cannot access local variable 'total' before assignment on the first expense it processes.
What you know
The function uses a nested process_expense() function that tries to accumulate a running total. The outer function defines total = 0.0, and the inner function does total += expense.amount. But it crashes immediately.
Strangely, the categories dict (also defined in the outer scope) works fine with categories[cat] = ... inside the nested function.
Hints
Python
Python ready
Test Output
▶
Click "Run Tests" to execute your code