[docs]class InvalidFactorialError(RuntimeError):
"""Error generated if an invalid factorial input is given."""
[docs]def factorial(n: int) -> int:
"""Computes the factorial through a recursive algorithm.
Parameters
----------
n: int
A positive input value.
Returns
-------
int
Returns the computed factorial.
Raises
------
InvalidFactorialError
If `n` is less than 0.
Examples
--------
>>> pathpy.factorial(1)
1
"""
if n < 0:
raise InvalidFactorialError(f"n is less than zero: {n}")
elif n == 0:
return 1
return n * factorial(n - 1)