I am trying to make a function that allows a user to input a number and the result will be a list containing Fibonacci numbers up to the input and one above if the input is not in the series. For example, input of 4
will return [0, 1, 1, 2, 3, 5]
but input of 3
would return [0, 1, 1, 2, 3]
. I have managed to do this using the function below :
def fibonacci(n):series = [0]if (n == 0):passelse:series.append(1)if (n == 1):passelse:while(series[len(series)-1] < n):newValue = series[len(series)-1] + series[len(series)-2]series.append(newValue)print(series)
However, I would now like to be able to do this recursively, any ideas?