Advertisement
Guest User

fib_iter

a guest
Oct 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. class FibonacciIterator:
  2.     def __init__(self, max):
  3.         self.max = max
  4.     def __iter__(self):
  5.         return self
  6.  
  7.     def __next__(self):
  8.         fib = self.x
  9.         if fib > self.max:
  10.             raise StopIteration
  11.         self.x, self.y = self.y, self.x + self.y
  12.         return fib
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement