-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterators.py
More file actions
30 lines (26 loc) · 701 Bytes
/
iterators.py
File metadata and controls
30 lines (26 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import time
class FiboIter():
def __iter__(self):
self.n1 = 0
self.n2 = 1
self.counter = 0
return self
def __next__(self):
if self.counter == 0:
self.counter += 1
return self.n1
elif self.counter == 1:
self.counter += 1
return self.n2
else:
self.aux = self.n1 + self.n2
# self.n1 = self.n2
# self.n2 = self.aux
self.n1, self.n2 = self.n2, self.aux
self.counter += 1
return self.aux
if __name__ == '__main__':
fibonacci = FiboIter()
for element in fibonacci:
print(element)
time.sleep(0.05)