Iteration for Factorials
mensanator at aol.com
mensanator at aol.com
Tue Oct 23 13:25:16 EDT 2007
On Oct 23, 6:58 am, 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?
The fact that it returns 1 for negative x?
And didn't you see my followup message? About how the
example, as posted, doesn't even produce correct answers
for legal values of x?
> if not allowing negative numbers is so
> important for you,
Mathematical consistency is only important to _me_?
> add a if statement and raise a ValueError exception.
Not necessary when done correctly. Didn't you see my example?
More information about the Python-list
mailing list