Menu
Coddy logo textTech

支出の追加

CoddyのPythonジャーニー「Fundamentals」セクションの一部 — レッスン 70/77。

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のすべてのレッスン