class Fibonacci: | |
def __init__(self, limit): | |
self.limit = limit | |
self.a, self.b = 0, 1 | |
def __iter__(self): | |
return self | |
def __next__(self): | |
if self.a > self.limit: | |
raise StopIteration | |
val = self.a | |
self.a, self.b = self.b, self.a + self.b | |
return val | |
for i in Fibonacci(100): | |
print(i) |