+ 1

For following recursive function,will recursion work for fib(x-1) first & then on fib(x-2) or will recursion work simultaneously

def fib(x): if x == 0 or x == 1: return 1 else: return fib(x-1) + fib(x-2) print(fib(4))

25th Jun 2017, 6:23 AM
Chinmay Upadhye
3 Answers
+ 1
since python starts left to right then fib(x-1) works first
25th Jun 2017, 3:31 PM
Mohamed Mirghani
Mohamed Mirghani - avatar
+ 1
Recursion will start from left to right only So fib(x-1) recurses first then by fib(x-2) but I am not clear with this iteration if any one knew help me with it
27th Jun 2017, 9:53 AM
S.Naveen Kumar
S.Naveen Kumar - avatar
0
I still don't follow this code. The output is 5, but how? Tried inserting some print statements but still not clicking for me
15th Jul 2017, 8:16 PM
Kevin Wojtas
Kevin Wojtas - avatar