Skip to content

Instantly share code, notes, and snippets.

@rajmayank
Created June 11, 2021 12:55
Show Gist options
  • Save rajmayank/80902f7308e3e5bdc5cd4c669ad07497 to your computer and use it in GitHub Desktop.
Save rajmayank/80902f7308e3e5bdc5cd4c669ad07497 to your computer and use it in GitHub Desktop.
Python-Iterators-FibonacciTill20-I
class FibonacciTill20:
def __init__(self):
self.n1, self.n2 = 0, 1
self.max = 20
def __iter__(self):
return self
def __next__(self):
self.n1, self.n2 = self.n2, self.n1 + self.n2
if self.n2 <= self.max:
return self.n2
else:
raise StopIteration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment