Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'else:': 0.03; 'infinite': 0.07; 'received:66.35': 0.09; 'recursion': 0.09; 'pm,': 0.11; 'subject:error': 0.12; 'def': 0.13; 'wrote:': 0.14; 'starts': 0.15; 'header:In-Reply-To:1': 0.22; 'function': 0.27; 'comparison': 0.31; 'depth': 0.31; 'import': 0.32; 'to:addr :python-list': 0.32; 'test': 0.33; 'received:192.168.1': 0.34; 'received:192': 0.34; 'correctly': 0.35; 'header:User-Agent:1': 0.35; 'latter': 0.35; 'received:192.168': 0.37; 'sequence': 0.38; 'but': 0.38; 'help': 0.39; 'to:addr:python.org': 0.39; 'works': 0.40; 'maximum': 0.62; '08:22': 0.84; 'exceeded': 0.86 Date: Fri, 29 Apr 2011 20:41:52 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110419 Thunderbird/3.1.9 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Fibonacci series recursion error References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1304135459 news.xs4all.nl 81474 [::ffff:82.94.164.166]:57080 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4340 On 04/29/2011 08:22 PM, lalit wrote: > 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 You correctly test for n==1, but what about when n==2? When the recursion works its way down to fib(2), you call both fib(1) and fib(0), but the latter starts an infinite sequence of calls to fib(-1), fib(-2) and so on without end. Gary Herron