Learn Lambda Functions by Building an Expense Tracker - Step 32

Tell us what’s happening:

the task says i should Define a function named main, and without parameter. 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 record.
i have define function but the code was unable to pass.

Your code so far

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)

# User Editable Region

def main():
    expense['amount'], expenses
expenses = []

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36

Challenge Information:

Learn Lambda Functions by Building an Expense Tracker - Step 32

Welcome to the forum :wave: Glad to have you.

The instructions for this step say:

Define a function named main without parameters. Fill the function body with the expenses list you created at the beginning of this project.

The two issues you have, which are preventing you from fulfilling this requirement:

  1. You have the extra line after your function declaration, which shouldn’t be there.
  2. The line expenses = [] should be indented. In Python, indentation matters, as it is used by the computer to determine what block a line of code is part of. If the line expenses = [] is not indented, the computer will not recognize it as part of the function main().

Let me know if anything is unclear.

1 Like

Thanks, @ShadyHBedda !

Hi @Godliveth01,

Just for the sake of clarity, what @ShadyHBedda is meaning with this:

is the expression you wrote just under the declaration of the main function: that is not necessary for the request.

And again, as @ShadyHBedda has rightly clarified, the only thing you have to do is to find the right place for the expenses list according to the request, always putting attention to the python syntax conventions.

Happy coding!

1 Like