1def factorial(n):
2 fact = 1
3 for num in range(2, n + 1):
4 fact = fact * num
5 return(fact)
1def factorial(n):
2 if n == 0:
3 return 1
4 else:
5 return n * factorial(n-1)
6n=int(input("Input a number to compute the factiorial : "))
7print(factorial(n))
8
9
1#Assumes n is possitive
2def factorial(n):
3 return 1 if n <=1 else n*factorial(n-1)
1def fact(n):
2 if n==0 or n==1:
3 return 1
4 else:
5 return n*fact(n-1)
6print(fact(4)) #4 is the sample value it will returns 4!==> 4*3*2*1 =24
7#OR
8import math
9print(math.factorial(4))
1def factorial(n):
2 for x in range(n-1,0,-1):
3 n = n*x
4 if n == 0: return 1
5 if n < 0 : return False
6 return n
7
8factorial(5) # returns 120
9
10####### lambda Factorial ########
11
12factorial = lambda n: n*factorial(n-1) if n > 0 else 1
13#OR
14factorial = lambda n: n>0 and n*factorial(n-1) or 1
15
16######### Recursion ##########
17def factorial(n):
18 if n <= 0: return 1
19 else: return n * factorial(n-1)
20
21# Do not use big number XD