Menu
Coddy logo textTech

전체 지출 내역 보기

Coddy Python 여정의 Fundamentals 섹션에 포함된 레슨 — 77개 중 71번째.

challenge icon

챌린지

쉬움

모든 지출 내역을 확인하는 옵션(2)을 처리합니다.

지출 목록이 비어 있으면 다음을 출력합니다:

No expenses recorded yet.

그렇지 않으면 다음 형식으로 목록을 출력합니다:

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

이전에 입력된 지출이 23.1, 35.5, 99.99, 15.2라고 가정합니다. (해당 순서대로!)

직접 해보기

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

Fundamentals의 모든 레슨