Factorials
Gerhard Häring
gh at ghaering.de
Sat Jun 7 09:45:02 EDT 2003
Rogue9 wrote:
> Pardon me but could anyone enlighten me if python2.2 has a math function
> to call to do factorials of integers?
It has not.
> If not then is there a code snippet
> for doing such a thing available?I tried to write some code for this
> myself but with little success.
Enter the words 'python' and 'factorial' into the search field
http://google.com/ to find code that does this.
The recursive form is pretty much a direct form of the methematical
definition of the factorial:
def fkt(n):
if n == 0:
return 1
else:
return n * fkt(n-1)
If you're doing a lot with factorials, I think you should upgrade to
Python 2.3 already, because it has an optimized multiplication for longs.
-- Gerhard
More information about the Python-list
mailing list