Answers for "factorial pythom"

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
3

factorial in python

def fact(n):
  return 1 if (n==0 or n==1) else n*fact(n-1)
fact(3)
Posted by: Guest on August-07-2020

Python Answers by Framework

Browse Popular Code Answers by Language