Anonymous user
Factorial: Difference between revisions
Python: Functional with sample output
m (→[[Factorial function#ALGOL 68]]: use a more authentic DO OD loop.) |
(Python: Functional with sample output) |
||
Line 57:
return z
</python>
====Functional====
<python>from operator import mul
def factorial(n):
return reduce(mul, xrange(1,n+1), 1)
</python>
:Sample output:
:<python>
: >>> for i in range(6):
: print i, factorial(i)
:
: 0 1
: 1 1
: 2 2
: 3 6
: 4 24
: 5 120
: >>>
:</python>
===Recursive===
|