I am failing to understand what last return statement does and was wondering if someone could point me to some additional reading material def fib(n) if n ==o: return o if n == 1: return 1 else: return fib(n-1) + fib(n-2) I have run the debugger and added a print statement but that return fib(n-1) + fib( n-2) completely baffles me I called the function print fib(7) which gives me the correct answer of 13 but darned if I can follow the logic Thanks

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions.

A community for students.

I am failing to understand what last return statement does and was wondering if someone could point me to some additional reading material def fib(n) if n ==o: return o if n == 1: return 1 else: return fib(n-1) + fib(n-2) I have run the debugger and added a print statement but that return fib(n-1) + fib( n-2) completely baffles me I called the function print fib(7) which gives me the correct answer of 13 but darned if I can follow the logic Thanks

MIT 6.00 Intro Computer Science (OCW)
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

this function is recursive. The first two 'returns' are the base case. The last one is the recursive call. it calls the function fib() twice with the arguments n-1 and n-2. The Wikipedia entries for recursion is pretty good: http://en.wikipedia.org/wiki/Recursion http://en.wikipedia.org/wiki/Recursion_(computer_science) I'm pretty sure there was an explanation of recursion in one of the lectures (2008). It is not an easy concept to grasp when first exposed to it (my opinion) but when you get it it's cool. Definitely need to take the time to understand it. images help after you've thought about it a while https://www.google.com/search?hl=en&tok=eMAnrt2ijUCk1wMdSZGBbA&pq=recursion+function&cp=12&gs_id=f&xhr=t&q=recursion+stack&newwindow=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&biw=1120&bih=642&um=1&ie=UTF-8&tbm=isch&source=og&sa=N&tab=wi&ei=oscAUKSqN7O02AWdq8WKCw#um=1&hl=en&newwindow=1&tbm=isch&sa=1&q=recursion&oq=recursion&gs_l=img.12..0l10.2232.2232.0.6724.1.1.0.0.0.0.166.166.0j1.1.0...0.0...1c.B5gOJwetQZc&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&fp=4ab5a515e740ecc2&biw=1120&bih=642 there is even a pik in there of the infamous recursive fib
thanks, I finally understand it

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Not the answer you are looking for?

Search for more explanations.

Ask your own question