Factorial in Python
Example for versions
Python 2.5.2,
Python 2.6.5
This example uses recursive factorial definition.
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
for n in range(16 + 1):
print "%d! = %d" % (n, factorial(n))
Comments
]]>blog comments powered by Disqus
]]>