Iteration for Factorials
Lou Pecora
pecora at anvil.nrl.navy.mil
Thu Oct 25 10:53:55 EDT 2007
In article <1193261568.712027.234520 at e9g2000prf.googlegroups.com>,
"mensanator at aol.com" <mensanator at aol.com> wrote:
> > def factorial(i):
> > fact=1.0
> > for n in xrange(i):
> > fact=n*fact
> > return fact
>
> Simple minded indeed.
>
> >>> factorial(3)
> 0.0
>
Whoops, should have xrange(i)+1 there. Or, better, xrange(2,n+1). Save a
multiplication. Just trying to show the OP the scheme for iteration
here.
--
-- Lou Pecora
More information about the Python-list
mailing list