The maximum depth of the Python interpreter stack is limited to 1000 calls by default. You can get it by import sys; sys.getrecursionlimit() and set a new value to sys.setrecursionlimit(new_value)
- Gennadiy <gennad.zlo...@gmail.com> On Mon, Aug 1, 2011 at 4:11 PM, jc <chen...@gmail.com> wrote: > # Get Fibonacci Value > # Fibonacci(N) = Fibonacci(N-1) + Fibonacci(N-2) > # > # n = 900 is OK > # n = 1000 is ERROR , Why > # > # What Wrong? > # > > cache = [] > > def fibo( n ): > > try: > if cache[n] != -1: > return cache[n] > else: > if 0 == n: > r = 0 > elif 1 == n: > r = 1 > else: > r = fibo(n-1) + fibo(n-2) > > cache[n] = r > return r > except: > print "EXCEPT: " + str(n) > > > if __name__ == '__main__': > > # This n = 900 is OK > # But n = 1000 is ERROR > > n = 900 > cache = range(0 , n + 1 , 1) > > for i in cache: > cache[i] = -1 > > print "Fibo(" + str(n) + ") = " + str(fibo(n)) > print "\n" > print "\n" > > -- > http://mail.python.org/mailman/listinfo/python-list >
-- http://mail.python.org/mailman/listinfo/python-list