-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiterators.py
39 lines (32 loc) · 885 Bytes
/
iterators.py
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
31
32
33
34
35
36
37
38
39
#Serie de fibonnacci
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
#Swapping
self.n1, self.n2 = self.n2, self.aux
self.counter += 1
return self.aux
if __name__ == "__main__":
num = int(input("break counter: "))
fibonnacci = FiboIter()
for element in fibonnacci:
if fibonnacci.counter == num:
raise StopIteration
else:
print(element)
time.sleep(1)