Menu
CoddyTech

支出を追加する

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

challenge icon

チャレンジ

簡単

ユーザーが経費を追加するオプション(1)を処理します。

  1. プログラムの開始時に、空の経費リストを初期化します
  2. ユーザーが選択肢として 1 を選んだら、ユーザーからもう1つ入力を受け取り、それを float として経費リストに追加します。
  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

基礎のすべてのレッスン

自分で練習してみよう: Pythonオンラインコンパイラ