# File: ChapterRecursion/factorial.py # fact(n) computes factorial of n # Recursive Definition n!: 0! = 1 and n! = n * (n-1)! # n! = 1 * 2 * 3 .. * n """ Compute n!. Enter integer? 6 6 != 720 6 != 720 """ def factRec( n ): if ( n == 1 ) : return 1 else: return n * factRec( n-1 ) def fact( n ): ans = 1 for i in range(1,n+1): ans = ans * i return ans def main(): n = int(input( "Compute n!. Enter integer? " )) print(n, "!= ", factRec(n) ) print(n, "!= ", fact(n) ) main()