I copied the source code of a python program written by someone else on a tutorial forum and I have made a few modifications to it to match my own needs
the original was meant to run in the python shell i believe and i got it to run in the shell but I need to save it to python IDLE and run it from there
I am using python 3.2.3 IDLE btw
this is what I have written:
def fibonacci(previous=0,current=1):
n = int(input("Calculate fibonacci sequence value up to: "))
if previous > current:
previous,current = current, previous
yield previous
yield current
while True:
current,previous = previous+current,current
yield current
x = fibonacci()
for i in range(n):
print(next(x))
fibonacci()
it doesn’t run, like no errors pop up i just get the arrows: >>
that’s it nothing happens.
The program does start and runs through. Unfortunately, by using
yieldin the function, you make it a generator, and the generator gets only constructed in the last line, but never evaluated.Instead, you want to outdent the last four lines: