I need to make a program that asks for the amount of Fibonacci numbers printed and then prints them like 0, 1, 1, 2... but I can't get it to work. My code looks the following:
a = int(raw_input('Give amount: ')) def fib(): a, b = 0, 1 while True: yield a a, b = b, a + b a = fib() a.next() 0 for i in range(a): print a.next(), ;
(b,a+b)using the current values ofaandb, then it unpacks that tuple when assigning it toa,b. (Technically speaking Python can do some optimization, but I'm ignoring this for now).