The right way is:<br><br>import operator<br>def fact(x):<br>    return reduce(operator.mul, xrange(1,x+1))<br><br><div><span class="gmail_quote">On 10/22/07, <b class="gmail_sendername">Paul Rudin</b> <<a href="mailto:paul.nospam@rudin.co.uk">
paul.nospam@rudin.co.uk</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">"<a href="mailto:mensanator@aol.com">mensanator@aol.com
</a>" <<a href="mailto:mensanator@aol.com">mensanator@aol.com</a>> writes:<br><br>> On Oct 22, 7:50 am, Duncan Booth <<a href="mailto:duncan.bo...@invalid.invalid">duncan.bo...@invalid.invalid</a>> wrote:
<br>>> Py-Fun <<a href="mailto:lorna.bu...@gmail.com">lorna.bu...@gmail.com</a>> wrote:<br>>> > I'm stuck trying to write a function that generates a factorial of a<br>>> > number using iteration and not recursion.  Any simple ideas would be
<br>>> > appreciated.<br>>><br>>> This version avoids doing anything fancier than adding 1, so it should be<br>>> simple enough for anyone:<br>>><br>>> def factorial(e):<br>>>     a = 1
<br>>>     for b in range(e):<br>>>         c = 0<br>>>         for j in range(b, -1, -1):<br>>>             for d in range(a):<br>>>                 c += 1<br>>>         a = c<br>>>     return a
<br>><br>> Not simple enough for my taste:<br>><br>>>>> import gmpy<br>>>>> gmpy.fac(10)<br>> mpz(3628800)<br><br>I haven't followed all this thread, but has anyone yet done:<br><br>
import operator<br>def fact(x):<br>    return reduce(operator.mul, xrange(1,x))<br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a><br></blockquote>
</div><br><br clear="all"><br>-- <br>Rafael Sachetto Oliveira<br><br>Sir - Simple Image Resizer<br><a href="http://rsachetto.googlepages.com">http://rsachetto.googlepages.com</a>