支出を追加する
CoddyのGDScriptジャーニー「基礎」セクションの一部。レッスン 85/92。
チャレンジ
簡単選択肢 1 を処理して、経費を追加します。前の手順で書いた内容はすべて残してください。
- ループの前に、経費用の空の配列を作成します:
var expenses: Array[float] = [] - 選択肢が
"1"の場合、もう1行読み取り、float()で変換してexpensesに追加します - 次を出力します:
Expense added successfully!"5" に対する if を、新しい "1" に対する if の下の elif に変更します。
自分で試してみよう
extends Node
func _ready():
print("Welcome to the Daily Expense Tracker!")
# メニューを一度だけ表示する
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:
# ユーザーの選択を取得する
var choice := OS.read_string_from_stdin()
if choice == "5":
# プログラムを終了する
print("Exiting the Daily Expense Tracker. Goodbye!")
break
基礎のすべてのレッスン
自分で練習してみよう: GDScriptオンラインコンパイラ