[Tutor] learning recursion

Mark Lawrence breamoreboy at yahoo.co.uk
Sat Feb 8 23:22:25 CET 2014


On 08/02/2014 10:06, rakesh sharma wrote:

Please do not top post on this list.

> I got my definition wrong
>
> the code should be more like this
>
> def fib(n):
> if n==0:
> return

What does the above line return?  As others have already said what 
happens if n is negative?

> elif n==1:
> return 1
> elif n==2:
> return 1
> else:
> return fib(n-2) + fib(n-1)
>
> thanks,
> rakesh
>

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com




More information about the Tutor mailing list