支出の追加
CoddyのPythonジャーニー「Fundamentals」セクションの一部 — レッスン 70/77。
チャレンジ
簡単ユーザーが支出を追加するオプション (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