Menu
CoddyTech

Recap - Factorial

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

challenge icon

Challenge

Easy

The 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 = 6
  • 5! is 1 x 2 x 3 x 4 x 5 = 120
  • 1! is 1, and 0! is also 1

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:

120

Try it yourself

extends Node

func _ready():
	# Read n, then print n! (the factorial of n)
	pass

All lessons in Fundamentals

Practice on your own: Online GDScript compiler