Drill

ProblemsPython › warmup

Factorial

easywarmupPython

Return n! — the product of every integer from 1 to n.

factorial(n: int) → int

Solve it in the editor →

Where you start

def factorial(n: int) -> int:
    

Worked examples

CallResult
factorial(0)1
factorial(1)1
factorial(5)120
factorial(10)3628800

Hint

Start an accumulator at 1 and multiply up to n. A loop is plenty.

Reference solution in Python
def factorial(n: int) -> int:
    acc = 1
    for i in range(2, n + 1):
        acc *= i
    return acc

The same problem in another language

More warmup problems in Python