How to calculate the factorial

The factorial is a mathematical operation that calculates the product of all the numbers up to the specified integer.

For example, the factorial of 5 would be 1*2*3*4*5 = 120. With our code we can do the following:

>>> from my_module.factorial import factorial
>>> factorial(5)
120

Module factorial

This module supplies one function, factorial() to calculate the factorial of an integer. You can imported like this:

>>> from my_module.factorial import factorial

The function Factorial

The function factorial is also well documented.

my_module.factorial.factorial(n)

Function to calculate the factorial of a number. First import, and then use, for example:

>>> factorial(5)
120
>>> factorial(-1)
Traceback (most recent call last):
    ...
ValueError: n must be >= 0
Parameters:n (int) – Number to calculate the factorial
Returns:The calculated factorial
Return type:int