Recap - Sigma Function
Part of the Fundamentals section of Coddy's GDScript journey. Lesson 55 of 92.
Challenge
EasyWrite a function named sigma with one int parameter n. It returns the sum of all the whole numbers from 1 to n, both included.
For example, sigma(5) returns 15, because 1 + 2 + 3 + 4 + 5 = 15.
The tests call sigma() themselves and check the value it returns. Do not call it, and do not print anything. The file needs only the function: no extends Node and no _ready().
Try it yourself
func sigma(n: int):
# Write code here
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