-
Notifications
You must be signed in to change notification settings - Fork 0
/
fibonacci.py
executable file
·56 lines (38 loc) · 916 Bytes
/
fibonacci.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python3
def fib(max):
a, b = 0, 1
while a < max:
yield a
a, b = b, a + b
glob = 100
class Fib :
def __init__(self, max) :
self.max = max
def __iter__(self) :
self.a = 0
self.b = 1
return(self)
def __next__(self) :
if self.a > self.max :
raise StopIteration
res = self.a
self.a, self.b = self.b, self.a + self.b
return res
def geta(self) :
return self.a
def getmax(self) :
return self.max
def getglob(self) :
return glob
for i in fib(100) :
print(i, end=' ')
print("\n ========================= \n")
#l = list(fib(50))
#print(l)
f = Fib(100)
for i in f :
print(i, end=' ')
print("\n ========================= \n")
print(" f.a:{}".format(f.geta()))
print(" f.max:{}".format(f.getmax()))
print(" f.glob:{}".format(f.getglob()))