Iteration for Factorials
Duncan Booth
duncan.booth at invalid.invalid
Mon Oct 22 08:50:49 EDT 2007
Py-Fun <lorna.burns at gmail.com> wrote:
> I'm stuck trying to write a function that generates a factorial of a
> number using iteration and not recursion. Any simple ideas would be
> appreciated.
>
This version avoids doing anything fancier than adding 1, so it should be
simple enough for anyone:
def factorial(e):
a = 1
for b in range(e):
c = 0
for j in range(b, -1, -1):
for d in range(a):
c += 1
a = c
return a
More information about the Python-list
mailing list