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.5 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6582575b8089f85b8b92d7c8 Step 34 20 step-34

--description--

Once you have the expense details, you need to call the add_expense function to add the new expense to the expenses list.

After getting the amount and category using input(), call the add_expense function, passing three arguments: expenses, amount and category.

  • expenses is the empty list created in the main function earlier in this project.
  • amount is the amount of the expense.
  • category is the category of the expense.

--hints--

You should call the add_expense() function within your if statement.

({ test: () => assert(runPython(`len(_Node(_code).find_function("main").find_whiles()[0].find_bodies()[0].find_ifs()[0].find_bodies()[0].find_calls("add_expense")) == 1`)) })

You should pass three arguments to your add_expense() call: expenses, amount, and category. The order matters.

({ test: () => assert(runPython(`_Node(_code).find_function("main").find_whiles()[0].find_bodies()[0].find_ifs()[0].find_bodies()[0].has_call("add_expense(expenses, amount, category)")`)) })

Your add_expense() call should come after the assignment of amount and category.

({ test: () => assert(runPython(`_Node(_code).find_function("main").find_whiles()[0].find_bodies()[0].find_ifs()[0].find_bodies()[0].is_equivalent("amount = float(input('Enter amount: '))\\ncategory = input('Enter category: ')\\nadd_expense(expenses, amount, category)")`)) })

--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 = []
    while True:
        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')

        choice = input('Enter your choice: ')
--fcc-editable-region--
        if choice == '1':
            amount = float(input('Enter amount: '))
            category = input('Enter category: ')

--fcc-editable-region--