+ 2
Fibonacci problem
How can I solve fibo problem with recursive function? Plz don't say the answer and just give me a hint. Thanks
5 Answers
+ 3
āSaeed.Mohammadi.Aghdam ,
there is a short tutorial for recusion in python available. read the description carefully. you should be able to implement the fibonacci problem.
https://www.sololearn.com/learn/Python/2465/?ref=app
if you get stuck, link your code here.
happy coding!
+ 1
Hi! You build a function f(n) that contains a base case for n < 2 that returns 1. In every other case the functon will return the sum of what the funtion returns when its argument is n-1 respektive n-2.
+ 1
Thanks, I think the recursive function start from the end to start or backward method. That thought is challenging me. As I know, you said recursive func could write from the start to the end like vice versa?
0
Thanks,
0
I saw the answer by someone, but it's not what Sololearn gives us (the body of the code - the input, the def and the function call), that answer is really close to. So I modified it a little bit: in the def of the function fibonacci(n), I defined another function that returns the nth number in the sequence, and at the end of the def of function fibonacci(n), I put a loop to print the sequence. I almost borrowed everything from the answer I have talked above, just added one more def.
Follow the hint provided by Sololearn (the base condition), and f(n) = f(n-1) + f(n-2).
Sorry for my English.