支出を追加する
CoddyのPythonジャーニー「基礎」セクションの一部。レッスン 70/77。
チャレンジ
簡単ユーザーが経費を追加するオプション(1)を処理します。
- プログラムの開始時に、空の経費リストを初期化します
- ユーザーが選択肢として
1を選んだら、ユーザーからもう1つ入力を受け取り、それをfloatとして経費リストに追加します。 - 追加した後、次の内容を出力します。
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オンラインコンパイラ