22
loading...
This website collects cookies to deliver better user experience
def fact(n):
if n==1 or n==0: #Base condition
return 1
else:
return n * fact(n-1) # recursion function calling
num=7
print("the factorial of" ,num, "is ", fact(num)) #function calling
the factorial of 7 is 5040
fact(n) #main function
return 7 * fact(6) #recursive function first call
return 7 * 6 *fact(5) #recursive function 2nd call (the value of fact(6) is 6 * fact(5))
return 7*6*5*fact(4) #recursive function 3rd call
return 7*6*5*4 *fact(3) #recursive function 4th call
return 7*6*5*4*3*fact(2) #recursive function 5th call
return 7*6*5*4*3*2*fact(1) #recursive function 6th call
return 7*6*5*4*3*2*1 #recursive function 7th call