(I'm in a basic computer science class, and this is homework)
I am trying to create a basic fibonacci sequence with "n" as the parameter.
what I have so far seems to be working fine when I run the program in idle
def fibonacci(n):
a=0
b=1
n = input("How high do you want to go? If you want to go forever, put 4ever.")
print(1)
while stopNumber=="4ever" or int(stopNumber) > a+b:
a, b = b, a+b
print(b)
fibonacci(n)
but when I try to run the program so that it displays the info I get this error
Traceback (most recent call last):
File "C:/Users/Joseph/Desktop/hope.py", line 10, in <module> fibonacci(n)
NameError: name 'n' is not defined
Any idea how I can fix this?
Since your
fibonacci
function is taking an input there isn't exactly a need to pass a parameter. But in the case of your errorn
isn't defined in the global scope. I would just get rid of then
parameter. Also, just replacestopNumber
withn
.