osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dictionary


Le 24/02/2019 ? 05:21, Himanshu Yadav a ?crit?:
> fibs={0:0,1:1}
> def rfib(n):
>        global fibs
>         if not fibs.get(n):
>                  fibs[n]=rfib(n-2)+rfib(n-1)
>          return fibs[n]
> 
> Why it is gives error??
> 

Nothing to do with the malfunction, but you dont need
to define fibs as global since you dont remap "fibs"
in side the function.

As explained by Peter, when n equals 0, not fibs.get(n)
will return True and recursivity goes on with n=-1, -2
until you reach the maximum allowed number of recursion
depth