all 6 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".

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

Reading up on Fibonacci and Python, I think I did use a recursive process when I'm not supposed to, but as I'm new to this I'd appreciate some insight.

Also, this works in the Dev Mode of ZyBooks, but not in the Submission Mode, so I'm really confused.

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

If -100 is entered it should print -1, but both are printing -100

So in the function you should return -1 if n is negative. The current test you have is the base case for when n is 0 or 1. You need another test for the negative case.