Re: Iteration for Factorials
- From: Duncan Booth <duncan.booth@xxxxxxxxxxxxxxx>
- Date: 22 Oct 2007 12:50:49 GMT
Py-Fun <lorna.burns@xxxxxxxxx> wrote:
I'm stuck trying to write a function that generates a factorial of aThis version avoids doing anything fancier than adding 1, so it should be
number using iteration and not recursion. Any simple ideas would be
appreciated.
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
.
- Follow-Ups:
- Re: Iteration for Factorials
- From: mensanator@xxxxxxx
- Re: Iteration for Factorials
- References:
- Iteration for Factorials
- From: Py-Fun
- Iteration for Factorials
- Prev by Date: Re: Iteration for Factorials
- Next by Date: Re: Iteration for Factorials
- Previous by thread: Re: Iteration for Factorials
- Next by thread: Re: Iteration for Factorials
- Index(es):
Relevant Pages
|