Python Forum
Linear Fibonacci sequence - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Linear Fibonacci sequence (/thread-8583.html)



Linear Fibonacci sequence - Tawnwen - Feb-27-2018

Currently learning Python recursion and stuck on how to write linear-time fib function:

def goodfib(k):
    if k == 0: return 0, 0, 1
    if k == 1: return 1, 0, 1
    u = goodfib(k - 1)
    ### fill in one line of code here to finish the goodfib function
This is the code the teacher gave us that we're to finish with a single line of code. The last number (1) returned in the base cases, btw, is just a measurement of the # of iterations. So you could pretend it wasn't there for all intents and purposes. Any help?


RE: Linear Fibonacci sequence - nilamo - Feb-27-2018

What is u? How do you calculate the next number of the sequence?