Files
2024-01-24 19:52:36 +01:00

2.1 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6582575b8089f85b8b92d7c8 Schritt 33 20 step-33

--description--

After getting 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 have add_expense(expenses, amount, category) in your if statement.

({ test: () =>
  {
    const transformedCode = code.replace(/\r/g, "");        
    const foo = __helpers.python.getDef("\n"+transformedCode, "main");
    const {function_body} = foo;    
    assert(function_body.match(/^\s+if\s+choice\s*==\s*("|')1\1\s*:\s*amount\s*=\s*float\s*\(\s*input\s*\(\s*("|')Enter\samount:\s\2\s*\)\s*\)\s*category\s*=\s*input\s*\(\s*("|')Enter\scategory:\s\3\s*\)\s*add_expense\s*\(\s*expenses\s*,\s*amount\s*,\s*category\s*\)/m));
  }
})

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