After the print() call, call the print_expenses function to display all the expenses that have been added so far. Pass the expenses list as the argument
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Help button located on the challenge. This button only appears if you have tried to submit an answer at least three times.
The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.
Thank you.
Please post your code, a link to the Step, and a description of how you are stuck (don’t just copy-paste the error message)
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: ')
if choice == '1':
amount = float(input('Enter amount: '))
category = input('Enter category: ')
add_expense(expenses, amount, category)
elif choice == '2':
print('\nAll Expenses:')
expenses()
print_expenses()
pass
Please post a link to the Step and a description of how you are stuck (don’t just copy-paste the error message)
Please post a description of how you are stuck (don’t just copy-paste the error message)
Step 44Passed
After theprint()
call, call theprint_expenses
function to display all the expenses that have been added so far. Pass theexpenses
list as the argument.
So looking at your code one of those calls will pass if you add an argument to it. What are you having trouble with?