Learn Lambda Functions by Building an Expense Tracker - Step 25

Tell us what’s happening:

I removed pass and I followed the instructions but I can’t make my code pass, what am I doing wrong?

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 (lambda expense: expense["amount"])

# User Editable Region


expenses = []

Your browser information:

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

Challenge Information:

Learn Lambda Functions by Building an Expense Tracker - Step 25

2 Likes

Replace pass with a lambda function that has expense as its parameter.

It might make sense here to return this value, but the instructions don’t ask for that.

3 Likes

Use a loop or a functional approach (like sum with a generator expression) to iterate over each expense and sum the amounts.

You can use sum with a generator expression to directly compute the total by summing up the amount values.

this is quite off topic, if you have your own questions about the curriculum challenges, please open your own topic using the Help button in the challenge

Thank you for your feedback. I understand the importance of staying on topic. I was just trying to helping him with a specific issue related to the curriculum challenge and wanted to ensure that my solution aligns with the requirements. If there’s a more appropriate way to address this or if you have any further guidance, please let me know. I appreciate your assistance!

what you are saying doesn’t help passing this step, which requires only creating the lambda function. Maybe you want to try to solve the steps yourself before helping?

1 Like

Thanks! I feel so dumb right now, I was overthinking!

1 Like

Thank you so much. / Muchas gracias.

2 Likes

No reason to feel dumb it’s actually smart to realize the lambda doesn’t do anything by itself unless it’s returned. Shows you are thinking critically.

1 Like

– removed

What the hell, i too was overthinking…

Glad you got it and welcome to the forum :wave:

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.

1 Like