Iteration for Factorials

tokland at gmail.com tokland at gmail.com
Tue Oct 23 07:58:56 EDT 2007


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.




More information about the Python-list mailing list