Recap - Dynamic Input
Part of the Fundamentals section of Coddy's GDScript journey. Lesson 50 of 92.
Challenge
EasyWrite a program that reads a list of whole numbers whose length is given in the input.
The first input line tells you how many numbers follow. Read that many numbers, one per line, and print their sum. The first number is a count, so it is not part of the sum.
For example, for this input:
3
1
5
6the program prints:
12because 3 numbers follow, and 1 + 5 + 6 = 12.
Try it yourself
extends Node
func _ready():
# Read the count, then read and add up that many numbers
pass
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsInteger DivisionModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators10Functions
Declare a FunctionArgumentsReturnReturn TypesRecap - Sigma FunctionRecap - Validation FunctionDefault Values5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Ternary OperatorPractice on your own: Online GDScript compiler