fibonacci | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

fibonacci

i didnt know how to do the fibonacci project because I didn't quite well understand how recursion works I understand the base case but the rest is kinda blurry for me any tips

24th Feb 2021, 9:57 AM
Med Hedi Bejaoui
Med Hedi Bejaoui - avatar
1 Answer
+ 2
base case = case to stop recursion (loop by calling function itself), ok? fibonacci rules: F(i) = F(i-1)+F(i-2), and F(0) = 0, F(1) = 1, right? def fibonnacci(n): if n < 0: raise Exception() if n in (0,1): return n; return fibonnacci(n-1)+fibonnacci(n-2)
24th Feb 2021, 3:11 PM
visph
visph - avatar