Menu
Coddy logo textTech

View All Expenses

Part of the Fundamentals section of Coddy's Python journey. Lesson 71 of 77.

challenge icon

Challenge

Easy

Handle the option to view all the expenses (2).

If the expenses list is empty, output:

No expenses recorded yet.

Otherwise, output the list in the following format:

Your expenses:
1. 23.1
2. 35.5
3. 99.99
4. 15.2

Assuming the expenses entered before were 23.1, 35.5, 99.99 and 15.2. (In that order!)

Try it yourself

print("Welcome to the Daily Expense Tracker!")

# Display menu once
print("\nMenu:")
print("1. Add a new expense")
print("2. View all expenses")
print("3. Calculate total and average expense")
print("4. Clear all expenses")
print("5. Exit")

# Initialize an empty list to store expenses
expenses = []

while True:
    # Get user choice
    choice = input()
    
    if choice == "1":
        # Add a new expense
        amount = float(input())
        expenses.append(amount)
        print("Expense added successfully!")

    elif choice == "5":
        # Exit the program
        print("Exiting the Daily Expense Tracker. Goodbye!")
        break

All lessons in Fundamentals

Practice on your own: Online Python compiler