Menu
Coddy logo textTech

Add Expense

Part of the Fundamentals section of Coddy's Python journey — lesson 70 of 77.

challenge icon

Challenge

Easy

Handle the option where the user adds an expense (1).

  1. Initialize in the start of the program an empty expenses list
  2. When the user selects 1 as a choice, get another input from the user, a float, and add its value to the expenses list.
  3. After adding, output:
Expense added successfully!

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

while True:
    # Get user choice
    choice = input()

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

All lessons in Fundamentals