factorial()
Compute the factorial of a non-negative integer.
Usage
factorial(n)Returns the product of all positive integers less than or equal to n. By convention, factorial(0) is 1.
Parameters
n: int-
A non-negative integer whose factorial is to be computed.
Returns
int-
The factorial of
n.
Raises
ValueError-
If
nis negative.
Examples
>>> factorial(5)
120
>>> factorial(0)
1Factorials grow very quickly:
>>> factorial(10)
3628800
>>> factorial(20)
2432902008176640000Works with small values too:
>>> factorial(1)
1
>>> factorial(2)
2