Files
task1-2/pyfiles/factorial.py
T
2024-03-31 21:44:11 +03:00

12 lines
201 B
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
def factorial(x):
    ans = 1
    if x < 0:
        raise ValueError('x must be greater than 0')
    for i in range(1, x+1):
        ans *= i
    
    return ans