Python - Factorial of a Number without using Recursion
I have given here python program to find the facorial of a number without using Recursion.
This code is tested with Python version 2.6
def Fact(n): result = 1; i = 0; if( n <= 1): return 1 for i in range(2, n + 1): result = result * i; return result; print "Program to find Factorial of a Number" val = 0 print "Enter a number: ", val = input() print val, "! = ", Fact(val) #sample output #Program to find Factorial of a Number #Enter a number: 5 #5 ! = 120
|