Back to Freecodecamp

Step 32

curriculum/challenges/english/blocks/learn-lambda-functions-by-building-an-expense-tracker/65824561f3478e5371a33ae5.md

latest1.3 KB
Original Source

--description--

The next step is to define the main function, which will be the entry point of the interactive expense tracker program.

Define a function named main without parameters. Fill the function body with the expenses list you created at the beginning of this project. You will use this list to store the expense records.

--hints--

You should define a function named main() without parameters.

js
({ test: () => assert(runPython(`
    import inspect    
    inspect.isfunction(main)
    sig = str(inspect.signature(main))
    sig == '()'
  `))
})

You should move the expenses list inside the main() function body.

js
({ test: () => assert(runPython(`_Node(_code).find_function("main").find_body().is_equivalent("expenses = []")`)) })

--seed--

--seed-contents--

py
def add_expense(expenses, amount, category):
    expenses.append({'amount': amount, 'category': category})
    
def print_expenses(expenses):
    for expense in expenses:
        print(f'Amount: {expense["amount"]}, Category: {expense["category"]}')
    
def total_expenses(expenses):
    return sum(map(lambda expense: expense['amount'], expenses))
    
def filter_expenses_by_category(expenses, category):
    return filter(lambda expense: expense['category'] == category, expenses)
--fcc-editable-region--

expenses = []
--fcc-editable-region--