Recap - Factorial
Part of the Fundamentals section of Coddy's GDScript journey. Lesson 47 of 92.
Challenge
EasyThe factorial of a whole number n is the product of all the whole numbers from 1 to n. It is written n!:
3!is 1 x 2 x 3 =65!is 1 x 2 x 3 x 4 x 5 =1201!is1, and0!is also1
Write a program that reads a whole number n (0 or more) and prints its factorial. Print only the number.
For the input 5, the output is:
120Try it yourself
extends Node
func _ready():
# Read n, then print n! (the factorial of n)
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