March 26 Generators

def fib():
 a, b = 2, 3
 while 1:
 yield a 
 a, b = b, a + b

import types
if type ( fib()) == types.GeneratorType:
 print "fib series."
 
 counter = 0
 for n in fib():
 print n
 counter += 1
 if counter == 15:
 break
 
This entry was posted in Assignments and tagged , . Bookmark the permalink.

Leave a comment