Integer multiplication overflow.
Aahz Maruch
aahz at panix.com
Sun Oct 8 01:45:04 EDT 2000
In article <8ronb6$75e$1 at nnrp1.deja.com>, <johnvert at my-deja.com> wrote:
>Hello,
>
>I wrote the following simple recursive factorial function in python:
>
>def fact(num):
> if num < 2: 1
> return num * fact(num - 1)
Change this to:
def fact(num):
if num < 2: 1L
return num * fact(num - 1)
Discovering why is left as an exercise for the reader.
WARNING: this will not work for num>9999. See recent posts on Fibonacci
sequence for the reason why (if you don't have them on your server, look
at DejaNews).
--
--- Aahz (Copyright 2000 by aahz at pobox.com)
Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
"[I have a] windmill fetish." --Darkhawk
More information about the Python-list
mailing list