[Tutor] learning recursion

Denis Heidtmann denis.heidtmann at gmail.com
Sat Feb 8 06:40:49 CET 2014


On Fri, Feb 7, 2014 at 9:05 PM, rakesh sharma
<rakeshsharma14 at hotmail.com> wrote:
> Hi
>
> Shouldn't your code be like this
>
> def fib(n):
> if n==0:
> return 0
> else:
> return n + fib(n-1)
>
> this works
>
>>>> for i in range(4):
> print fib(i)
>
> 0
> 1
> 3
> 6
>>>>

interesting, but the Fibonacci sequence is 1,1,2,3,5,8,13,...

-Denis H.


More information about the Tutor mailing list