Iteration for Factorials

cokofreedom at gmail.com cokofreedom at gmail.com
Tue Oct 23 08:09:13 EDT 2007


On Oct 23, 1:58 pm, tokl... at gmail.com wrote:
> On 22 oct, 23:39, "mensana... at aol.com" <mensana... at aol.com> wrote:
>
> > Nope, still doesn't work:
>
> > def fact(x):
> >         return reduce(operator.mul,xrange(1,x+1),1)
>
> > fact() should raise an exception if x is negative.
>
> So, where is the problem? if not allowing negative numbers is so
> important for you, add a if statement and raise a ValueError exception.

indeed, especially considering that fact(x) is essentially just a
lambda statement as Marco Mariani said.




More information about the Python-list mailing list