Python/maths/factorial_python.py
Ankur Chattopadhyay 7592cba417 psf/black code formatting (#1421)
* added sol3.py for problem_20

* added sol4.py for problem_06

* ran `black .` on `\Python`
2019-10-22 19:13:48 +02:00

22 lines
510 B
Python

def factorial(input_number: int) -> int:
"""
Non-recursive algorithm of finding factorial of the
input number.
>>> factorial(1)
1
>>> factorial(6)
720
>>> factorial(0)
1
"""
if input_number < 0:
raise ValueError("Input input_number should be non-negative")
elif input_number == 0:
return 1
else:
result = 1
for i in range(input_number):
result = result * (i + 1)
return result