home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / diveintopython / examples / fibonacci.py < prev    next >
Encoding:
Python Source  |  2004-05-05  |  532 b   |  22 lines

  1. """Fibonacci sequences using generators
  2.  
  3. This program is part of "Dive Into Python", a free Python book for
  4. experienced programmers.  Visit http://diveintopython.org/ for the
  5. latest version.
  6. """
  7.  
  8. __author__ = "Mark Pilgrim (mark@diveintopython.org)"
  9. __version__ = "$Revision: 1.2 $"
  10. __date__ = "$Date: 2004/05/05 21:57:19 $"
  11. __copyright__ = "Copyright (c) 2004 Mark Pilgrim"
  12. __license__ = "Python"
  13.  
  14. def fibonacci(max):
  15.     a, b = 0, 1
  16.     while a < max:
  17.         yield a
  18.         a, b = b, a+b
  19.  
  20. for n in fibonacci(1000):
  21.     print n,
  22.