maths.factorial

Factorial of a positive integer – https://en.wikipedia.org/wiki/Factorial

Attributes

n

Functions

factorial(→ int)

Calculate the factorial of specified number (n!).

factorial_recursive(→ int)

Calculate the factorial of a positive integer

Module Contents

maths.factorial.factorial(number: int) int

Calculate the factorial of specified number (n!).

>>> import math
>>> all(factorial(i) == math.factorial(i) for i in range(20))
True
>>> factorial(0.1)
Traceback (most recent call last):
    ...
ValueError: factorial() only accepts integral values
>>> factorial(-1)
Traceback (most recent call last):
    ...
ValueError: factorial() not defined for negative values
>>> factorial(1)
1
>>> factorial(6)
720
>>> factorial(0)
1
maths.factorial.factorial_recursive(n: int) int

Calculate the factorial of a positive integer https://en.wikipedia.org/wiki/Factorial

>>> import math
>>> all(factorial(i) == math.factorial(i) for i in range(20))
True
>>> factorial(0.1)
Traceback (most recent call last):
    ...
ValueError: factorial() only accepts integral values
>>> factorial(-1)
Traceback (most recent call last):
    ...
ValueError: factorial() not defined for negative values
maths.factorial.n