Menu
Coddy logo textTech

지출 추가

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

challenge icon

챌린지

쉬움

사용자가 지출을 추가하는 옵션(1)을 처리합니다.

  1. 프로그램 시작 시 빈 expenses 리스트를 초기화합니다.
  2. 사용자가 선택지로 1을 선택하면, 사용자로부터 float 형태의 입력을 하나 더 받고 그 값을 expenses 리스트에 추가합니다.
  3. 추가한 후, 다음을 출력합니다:
Expense added successfully!

직접 해보기

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

Fundamentals의 모든 레슨