Python Countdown

Simon Brunning simon.brunning at gmail.com
Fri Nov 11 14:41:06 EST 2005


On 11/11/05, john boy <xray_alpha_charlie at yahoo.com> wrote:
> I am running the following program from the example in "how to think like a
> computer scientist"
>
> def countdown(n):
>       if n ==0:
>            print "Blastoff!"
>       else:
>           print n
>           countdown (n-1)
>
> countdown (1000)
>
> When I set "n"= 1000 the program runs in interpreter and stops counting down
> at 14 instead of running all the way to "Blastoff".  If I set n = 985 it
> completes the program. If I set n=1200 it runs to 214 and stops.  Why is
> this program only counting to 986....Anybody have an answer??
> I am using Python 2.4.2

Look at this:

import sys
sys.getrecursionlimit()

It's set to 1000 by default. (Are you using IDLE or something? That
would explain where your other 14 levels of stack went.) You can
change it if you want to:

sys.setrecursionlevel(2000)

--
Cheers,
Simon B,
simon at brunningonline.net,
http://www.brunningonline.net/simon/blog/



More information about the Python-list mailing list