On Tue, Mar 11, 2008 at 10:38 AM, Joe Riopel <[EMAIL PROTECTED]> wrote: > On Mon, Mar 10, 2008 at 1:08 AM, Nathan Pinno <[EMAIL PROTECTED]> wrote: > > How do I factor a number? I mean how do I translate x! into proper > > Python code, so that it will always do the correct math? > > This should work to do x! (factorial of x). > > reduce(lambda x,y: x*y, range(1, x+1))
Sorry, the variable naming was confusing in that code. >>> def dofact(x): ... return reduce(lambda a,b: a*b, range(1,x+1)) ... >>> dofact(5) 120 >>> -- http://mail.python.org/mailman/listinfo/python-list