License Python Software Foundation License (Python 2.x)
Lines 17
Keywords
Fibonacci sequence (1) generator (1)
Included in this Library
Permissions
Viewable by Everyone
Editable by All Siafoo Users
Hide
Free your code from a slow death on your hard drive Join Siafoo Now or Learn More

Fibonacci Sequence Generator Atom Feed 0

In Brief Renders Fibonacci sequences, up to a given maximum value, using a generator function.
# 's
 1"""Fibonacci sequences using generators
2
3This program is part of "Dive Into Python", a free Python book for
4experienced programmers. Visit http://diveintopython.org/ for the
5latest 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
14def fibonacci(max):
15 a, b = 0, 1
16 while a < max:
17 yield a
18 a, b = b, a+b
19
20for n in fibonacci(1000):
21 print n,

Renders Fibonacci sequences, up to a given maximum value, using a generator function.