Back to Freecodecamp

Step 35

curriculum/challenges/english/blocks/learn-lambda-functions-by-building-an-expense-tracker/65824a1b16631c54fa524154.md

latest1.2 KB
Original Source

--description--

Next, add another print() call and pass the string '2. List all expenses'.

--hints--

You should print '2. List all expenses' in your while loop after the existing print() calls.

js
({ test: () => assert(runPython(`
call_lst = _Node(_code).find_function("main").find_whiles()[0].find_bodies()[0].find_calls("print")
test_lst = ["print('\\\\nExpense Tracker')", "print('1. Add an expense')", "print('2. List all expenses')"]
all(call_lst[n].is_equivalent(i) for n, i in enumerate(test_lst))
`)) })

--seed--

--seed-contents--

py
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)

def main():
    expenses = []
--fcc-editable-region--
    while True:
        print('\nExpense Tracker')
        print('1. Add an expense')
        
--fcc-editable-region--