> import os > def fib(n): > if n == 1: > return(n) > else: > return (fib(n-1)+fib(n-2)) > > list=fib(20) > print(list) > > The above function return the > return (fib(n-1)+fib(n-2)) > > > RuntimeError: maximum recursion depth exceeded in comparison > [36355 refs] > > can any one help
The first call to fib() recursively calls fib() twice. Each of those will call fib() twice. Each of those will call fib() twice. Pretty soon, you've got a lot of calls. Have a look at: http://en.literateprograms.org/Fibonacci_numbers_(Python). -- http://mail.python.org/mailman/listinfo/python-list