-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_pack.py
47 lines (35 loc) · 815 Bytes
/
lib_pack.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
#Iterative Method
def fibonacci_iterative(n):
fib_series = [0, 1]
while len(fib_series) < n:
fib_series.append(fib_series[-1] + fib_series[-2])
return fib_series[:n]
#Recursive Method
def fibonacci_recursive(n):
if n <= 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
else:
fib_series = fibonacci_recursive(n - 1)
fib_series.append(fib_series[-1] + fib_series[-2])
return fib_series
#Generator Method
def fibonacci_generator(n):
a, b = 0, 1
for _ in range(n):
yield a
a, b = b, a + b
def fib(n):
a,b = 0,1
while a < n:
print(a, end= '')
a,b = b, a+b
print()
class Trivial:
pass
if __name__ == "__main__":
import sys
fib(int(sys.argv[1]))