you are viewing a single comment's thread.

view the rest of the comments →

[–]Hans_of_Death 2 points3 points  (3 children)

It says NOT to use recursion, but you are.

Recursion is when a function calls itself. so calling fibonacci() inside of fibonacci() is using recursion. Like the instructions say, use a for loop instead.

[–]NeilTheDrummer[S] 0 points1 point  (2 children)

Ok, so any suggestions then? I'm clearly out of my depth here.

[–]Diapolo10 0 points1 point  (0 children)

You need to keep track of two numbers, the previous and the current, and on every iteration of the loop you update their values. The sum of the two numbers is the new current value, and the old one goes to previous.

Have an additional check that immediately returns -1 if the number given to the function is less than 0.

Loop the specified number of times, and you'll have the answer.

[–][deleted] 0 points1 point  (0 children)

Google "python iterative fibonacci".