Answers for "factorial of a number in python using function"

20

python calculate factorial

def factorial(n):
    fact = 1
    for num in range(2, n + 1):
        fact = fact * num
    return(fact)
Posted by: Guest on May-24-2020
2

factorial python

def factorial_iter(n):
    product = 1
    for i in range(n):
        product = product * (i+1)
    return product

def factorial_recursive(n):
    if n == 1 or n == 0:
        return 1
    return n * factorial_recursive(n-1)

# f = factorial_iter(5)
f = factorial_recursive(0)
print(f)
Posted by: Guest on January-11-2022
0

factorial python

def factorial(n)
    if n < 2:
        return 1
    else:
        return n * factorial(n - 1)
Posted by: Guest on October-23-2021

Code answers related to "factorial of a number in python using function"

Python Answers by Framework

Browse Popular Code Answers by Language