Learn Lambda Functions by Building an Expense Tracker - Step 17

Tell us what’s happening:

I am stuck it keeps telling me that there is an indentation error but idk how to solve it

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"]}')
    

# User Editable Region

def total_expenses(expenses):
    return sum(map(lambda expense: expense['amount'], expenses))


# User Editable Region

    return total
    
  total = sum(map(get_amount, expenses))
  return total


expenses = []

Your browser information:

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1

Challenge Information:

Learn Lambda Functions by Building an Expense Tracker - Step 17

Hi @saulitom2408!

The indention error is caused by the indention of the first return total line.

The following code block is not needed:

    return total
    
  total = sum(map(get_amount, expenses))
  return total

Double-check the following line:

return sum(map(lambda expense: expense['amount'], expenses))

The solution to the test is in there. Remember, the instruction wants you to return a lambda with expense as a parameter, and the value of the key 'amount' inside the expense dictionary.

Also, the lambda function will be an implicit return for this test.

I hope this helps. Happy Coding!

Thank you👍 I really appreciate it

1 Like