Learn Lambda Functions by Building an Expense Tracker - Step 9

Tell us what’s happening:

So i have already cleared this step but i don’t really understand why i must use the " inside the f string for the amount and category variables. Can someone please explain this to me.

Your code so far

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

# User Editable Region

def print_expenses(expenses):
    for expense in expenses:
        print(f'Amount: {expense["amount"]}, Category: {expense["category"]}')

# User Editable Region


expenses = []

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0

Challenge Information:

Learn Lambda Functions by Building an Expense Tracker - Step 9

Hi @Belmut,

With a dictionary, you have a key-value pair. When we want to get the value of something, we call the key of the pair. Keys are identified with quotations (single or double). So what we’re saying inside the f-string is: “Hey, inside expenses, give me the value associated with the key: 'amount'.” I hope this helps some.

1 Like

The problem is with the quotes in the f-string, here is the correct version:
print(f"Amount: {expense[‘amount’]}, Category: {expense[‘category’]}")

Hello welcome to the forum.

Please don’t post solution code, thanks

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.