Add Expense
Part of the Fundamentals section of Coddy's GDScript journey. Lesson 85 of 92.
Challenge
EasyHandle the choice 1, adding an expense. Keep everything you wrote in the previous steps.
- Before the loop, create an empty array for the expenses:
var expenses: Array[float] = [] - When the choice is
"1", read one more line, convert it withfloat()and append it toexpenses - 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
4Operators Part 1
Arithmetic OperatorsInteger DivisionModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators10Functions
Declare a FunctionArgumentsReturnReturn TypesRecap - Sigma FunctionRecap - Validation FunctionDefault Values13Iterating Over Arrays
Iterating Over ElementsIterating With IndexesIterating Over Strings Part 1Iterating Over Strings Part 216Daily Expense Tracker
Project OverviewExit The Program5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Ternary OperatorPractice on your own: Online GDScript compiler