Created
June 11, 2021 12:55
-
-
Save rajmayank/80902f7308e3e5bdc5cd4c669ad07497 to your computer and use it in GitHub Desktop.
Python-Iterators-FibonacciTill20-I
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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