# File: Erin/factorial.py # fact(n) computes factorial of n. Recursive. try big numbers # 0! = 1 # n! = n * (n-1)! #>>> # I compute n!. Enter n > 5 # Factorial of 5 = 120 # I compute n!. Enter n > 6 # Factorial of 6 = 720 # I compute n!. Enter n > 1 # Factorial of 1 = 1 # I compute n!. Enter n > // type just ENTER def fact( n ): if ( n == 0 ): return 1 else: return n * fact( n - 1 ) def main(): while True: #loop for ever n = input( "I compute n!. Enter n > " ) if (n == "") : #stop when type ENTER break n = eval( n ) #convert n from string to integer print("Factorial of %d = %d" % ( n, fact(n) )) main()