Listen, I know there are a thousand posts about this, and I've spent three hours looking at them all. I know there's a simple reason this code is not working, but I can't figure it out. When it runs, I only want it to return the nth term. I am new to python, and maybe there's some logic I'm not getting. So when I do this:
n = int(input("What Fibonacci number would you like to find? "))
def fib(n):
i = 0
present = 1
previous = 0
while i < n:
nextterm = present + previous
present = previous
previous = nextterm
i = i + 1
print nextterm
print(fib(n))
I get this:
1
1
2
3
5
None
When I do this:
n = int(input("What Fibonacci number would you like to find? "))
def fib(n):
i = 0
present = 1
previous = 0
while i < n:
nextterm = present + previous
present = previous
previous = nextterm
i = i + 1
return nextterm
print(fib(n))
I just get "1"
I have spent so much time on this and I am so confused. Someone please fix me!