# 10 examples of 'factorial in python' in Python

Every line of 'factorial in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure. ## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``13def factorial():14    """15    This function reads a number and computes its factorial16    """17    print("Problem: Factorial")1819    number = int(input())20    result = 12122    for n in range(2, number+1):23        result *= n2425    print(result)``
``2def factorial(n):3    fact = 14    for i in range(1,n+1):5        fact *= i6    return fact``
``1def factorial(n):2    res = 13    for i in range(2, n + 1):4        res *= i5    return res``
``9def factorial(n):10  if n is 0:11    return 112  else:13    return n * factorial(n-1)``
``42def factorial(n):43    """44    normal recursive two_sum45    :return: int46    """47    if n == 1 or n == 0:  # base case for n = 0, 148        return 149    else:  # recursive case when n > 150        return n * factorial(n - 1)``
``2def factorial(n):3    if(n==1):4        return 15    else:6        return(factorial(n-1)*n)``
``11def factorial(n):12		res = i = 113		while i <= n:14			res *= i15			i += 116		return res``
``11def factorial(n):12    """Define the factorial for fractions and negative numbers."""13    return gamma(n + 1)``
``34def inverse_factorial(number, round_up=True):35    '''36    Get the integer that the factorial of would be `number`.37    38    If `number` isn't a factorial of an integer, the result will be rounded. By39    default it'll be rounded up, but you can specify `round_up=False` to have40    it be rounded down.41    42    Examples:43    44        >>> inverse_factorial(100)45        546        >>> inverse_factorial(100, round_up=False)47        448        49    '''50    assert number >= 051    if number == 0:52        return 053    elif number < 1:54        return int(round_up) # Heh.55    elif number == 1:56        return 157    else:58        current_number = 159        for multiplier in itertools.count(2):60            current_number *= multiplier61            if current_number == number:62                return multiplier63            elif current_number > number:64                return multiplier if round_up else (multiplier - 1)``
``55def factorial(n):56    return np.prod(np.arange(1, n+1))``