I'm trying to make a list of numbers on a single line that follow the Fib sequence. I'm using the recursive method of Fib(n) = Fib(n-1)+Fib(n-2) and this gives me a single value of course, when I use:
return fib(n-1)+fib(n-2)
How can I make this loop and give me a list? For example:
[1,1,2,3,5,8,13]
if I typed in: 7
for n
.
OK, so in some ways I have fixed it. I now ask the user to input a value, say x, which is then used in a while loop. It passes the x value through the recursive fib function, appends this new value to a list and then decrements f by 1. Then I used list.reverse() to reverse the list so that the numbers appear in ascending order and I then print the list. This list has spaces between each number though, and I don't want that. Is there a solution to this?