지출 추가
Coddy Python 여정의 Fundamentals 섹션에 포함된 레슨 — 77개 중 70번째.
챌린지
쉬움사용자가 지출을 추가하는 옵션(1)을 처리합니다.
- 프로그램 시작 시 빈
expenses리스트를 초기화합니다. - 사용자가 선택지로
1을 선택하면, 사용자로부터float형태의 입력을 하나 더 받고 그 값을expenses리스트에 추가합니다. - 추가한 후, 다음을 출력합니다:
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