Learn Lambda Functions by Building an Expense Tracker - Step 4

Tell us what’s happening:

Attempting to append a dictionary to my list. Everything looks right, but the code doesn’t pass. I don’t understand what I’m doing wrong.

Your code so far


# User Editable Region

def add_expense(expenses, amount, category):
    my_dict = {'amount': amount, 'category': category}
    expenses.append(my_dict)

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0

Challenge Information:

Learn Lambda Functions by Building an Expense Tracker - Step 4

Welcome to the forum @jbamaker

Create a dictionary with a key 'amount' and value of the amount parameter and pass your new dictionary to the .append() call.

There are several things to fix here.

The first one is: you only need one key for this step.

Happy coding

I figured as much. TBH, this isn’t my first attempt. I’ve tried it with 1 key/value pair and got the same result. I understand the code is read top down, so I believe that I need to create the expenses list first, create the dictionary, and then append the dictionary to the list. I’m missing something and I can’t figure it out…

So the forum can assist please post your full code.

Use the following method to post code to the forum:

  1. On a separate line type three back ticks.
  2. On a separate line paste your code.
  3. On the last line type three back ticks. Here is a single back tick `

Happy coding

Ok, I see. I was overthinking it. I figured it out, lol. Thank you.

1 Like

hey i also stcuk at the same step could you help me

Please open a new thread

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.