Files
freeCodeCamp's Camper Bot 64697d4ca7 chore(i18n,learn): processed translations (#54988)
Co-authored-by: Naomi <commits@nhcarrigan.com>
2024-05-28 16:57:56 +09:00

2.4 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
65824c7b4e2da85597693dcf Step 28 20 step-28

--description--

Provide the other menu options by printing the following three strings in your while loop: '3. Show total expenses', '4. Filter expenses by category', and '5. Exit'. Keep adding the print() calls in order.

--hints--

You should have print('3. Show total expenses') in your while loop.

({ 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')", "print('3. Show total expenses')"]
all(call_lst[n].is_equivalent(i) for n, i in enumerate(test_lst))
`)) })

You should have print('4. Filter expenses by category') in your while loop.

({ 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')", "print('3. Show total expenses')", "print('4. Filter expenses by category')"]
all(call_lst[n].is_equivalent(i) for n, i in enumerate(test_lst))
`)) })

You should have print('5. Exit') in your while loop.

({ 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')", "print('3. Show total expenses')", "print('4. Filter expenses by category')", "print('5. Exit')"]
all(call_lst[n].is_equivalent(i) for n, i in enumerate(test_lst))
`)) })

--seed--

--seed-contents--

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')
        print('2. List all expenses')

--fcc-editable-region--