mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-24 13:31:07 +00:00
7592cba417
* added sol3.py for problem_20 * added sol4.py for problem_06 * ran `black .` on `\Python`
22 lines
510 B
Python
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
|