On Mar 11, 11:47 pm, Lie <[EMAIL PROTECTED]> wrote: > On Mar 10, 12:08 pm, 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? > > > Thanks in advance, > > Nathan P. > > Factorial algorithm is a very simple and common algorithm, and it's > one of the most basic of all recursive algorithm > def fact(x): > return x * fact(x - 1)
As an exercise (actually I forget), I'll let you figure out yourself why the above function doesn't work. There is only one simple line to be added and all's done. Hint: There are two important elements in all recursive algorithm, the catch-all return statement (which I've given you) and the conditioned return statement (which you've got to figure out yourself) -- http://mail.python.org/mailman/listinfo/python-list