- Iterative factorial
def fact_iter(n): # considering 0! for prod = 1
prod = 1
for i in range (1, n+1):
prod *= i
return prod
fact_iter(5)
- Recursive factorial
def fact_recur(n):
'''assume n >= 0'''
if n <= 1:
return 1
return n * fact_recur(n - 1)
fact_recur(5)