Menu
CoddyTech

Add Expense

Part of the Fundamentals section of Coddy's GDScript journey. Lesson 85 of 92.

challenge icon

Challenge

Easy

Handle the choice 1, adding an expense. Keep everything you wrote in the previous steps.

  1. Before the loop, create an empty array for the expenses: var expenses: Array[float] = []
  2. When the choice is "1", read one more line, convert it with float() and append it to expenses
  3. Then print:
Expense added successfully!

Turn the if for "5" into an elif under the new if for "1".

Try it yourself

extends Node

func _ready():
	print("Welcome to the Daily Expense Tracker!")

	# Display the 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 the choice of the user
		var choice := OS.read_string_from_stdin()

		if choice == "5":
			# Exit the program
			print("Exiting the Daily Expense Tracker. Goodbye!")
			break

All lessons in Fundamentals

Practice on your own: Online GDScript compiler