fibonacci() is from Diving Into Python by Mark Pilgrim
>>> def fibonacci():
... a,b = 0,1
... while a <= 4000000:
... yield a
... a,b = b, a + b
...
>>> total = 0
>>> for n in fibonacci():
... if n%2 == 0:
... total += n
...
>>> print total
4613732
Saturday, August 23, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment