Factorial in Python
Example for versions
Python 2.5.2,
Python 2.6.5
This example uses iterative method of calculating factorials.
def factorial(n):
if n == 0:
return 1
f = 1
for i in range(1, n + 1):
f *= i
return f
for n in range(16 + 1):
print "%d! = %d" % (n, factorial(n))
Comments
]]>blog comments powered by Disqus
]]>