Jan-06-2020, 06:41 AM
(This post was last modified: Jan-06-2020, 06:41 AM by sandeep_ganga.)
I would use something like,
Sandeep
GANGA SANDEEP KUMAR
def _factorial_sample_(n): if n == 0 or n == 1: return 1 else: #result = n * _factorial_sample_(n-1) print("\nGiven number to find factorial is ", n ,"\n") i=n fact=1 while(i>0): print( " ",fact," * ",i) fact=fact*i print("temp_computed_result= ",fact) i -= 1 print("\nfactorial of ",n," is : ", fact) return fact print(_factorial_sample_(5))
Output:python 6jan.py
Given number to find factorial is 5
1 * 5
temp_computed_result= 5
5 * 4
temp_computed_result= 20
20 * 3
temp_computed_result= 60
60 * 2
temp_computed_result= 120
120 * 1
temp_computed_result= 120
factorial of 5 is : 120
120
Best Regards,Sandeep
GANGA SANDEEP KUMAR