mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-06 21:00:24 -04:00
2.1 KiB
2.1 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 65824c7b4e2da85597693dcf | Schritt 27 | 20 | step-27 |
--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.
--hints--
You should have print('3. Show total expenses') in your while loop.
({ test: () =>
{
const transformedCode = code.replace(/\r/g, "");
const foo = __helpers.python.getDef("\n"+transformedCode, "main");
const {function_body} = foo;
assert(function_body.match(/^\s+print\s*\(\s*("|')3\.\sShow\stotal\sexpenses\1\s*\)/m));
}
})
You should have print('4. Filter expenses by category') in your while loop.
({ test: () =>
{
const transformedCode = code.replace(/\r/g, "");
const foo = __helpers.python.getDef("\n"+transformedCode, "main");
const {function_body} = foo;
assert(function_body.match(/^\s+print\s*\(\s*("|')4\.\sFilter\sexpenses\sby\scategory\1\s*\)/m));
}
})
You should have print('5. Exit') in your while loop.
({ test: () =>
{
const transformedCode = code.replace(/\r/g, "");
const foo = __helpers.python.getDef("\n"+transformedCode, "main");
const {function_body} = foo;
assert(function_body.match(/^\s+print\s*\(\s*("|')5\.\sExit\1\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 = []
--fcc-editable-region--
while True:
print('\nExpense Tracker')
print('1. Add an expense')
print('2. List all expenses')
--fcc-editable-region--