factorial of a positive integer https en wikipedia orgwikifactorial calculate the factorial of specified number n import math allfactoriali math factoriali for i in range20 true factorial0 1 traceback most recent call last valueerror factorial only accepts integral values factorial1 traceback most recent call last valueerror factorial not defined for negative values factorial1 1 factorial6 720 factorial0 1 calculate the factorial of a positive integer https en wikipedia orgwikifactorial import math allfactoriali math factoriali for i in range20 true factorial0 1 traceback most recent call last valueerror factorial only accepts integral values factorial1 traceback most recent call last valueerror factorial not defined for negative values calculate the factorial of specified number n import math all factorial i math factorial i for i in range 20 true factorial 0 1 traceback most recent call last valueerror factorial only accepts integral values factorial 1 traceback most recent call last valueerror factorial not defined for negative values factorial 1 1 factorial 6 720 factorial 0 1 calculate the factorial of a positive integer https en wikipedia org wiki factorial import math all factorial i math factorial i for i in range 20 true factorial 0 1 traceback most recent call last valueerror factorial only accepts integral values factorial 1 traceback most recent call last valueerror factorial not defined for negative values
def factorial(number: int) -> int:
    
    if number != int(number):
        raise ValueError("factorial() only accepts integral values")
    if number < 0:
        raise ValueError("factorial() not defined for negative values")
    value = 1
    for i in range(1, number + 1):
        value *= i
    return value


def factorial_recursive(n: int) -> int:
    
    if not isinstance(n, int):
        raise ValueError("factorial() only accepts integral values")
    if n < 0:
        raise ValueError("factorial() not defined for negative values")
    return 1 if n in {0, 1} else n * factorial(n - 1)


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    n = int(input("Enter a positive integer: ").strip() or 0)
    print(f"factorial{n} is {factorial(n)}")