File tree
Expand file treeCollapse file tree1 file changed
+9
-10
lines changed Expand file treeCollapse file tree1 file changed
+9
-10
lines changed Original file line number | Diff line number | Diff line change |
---|
|
6 | 6 | class Fibonacci:
|
7 | 7 |
|
8 | 8 | def __init__(self, N=None):
|
| 9 | +self.fib_array = [] |
9 | 10 | if N:
|
10 | 11 | N = int(N)
|
11 |
| -self.fib_array = [0] * (N + 1) |
12 |
| -self.fib_array[0] = 0 |
13 |
| -self.fib_array[1] = 1 |
| 12 | +self.fib_array.append(0) |
| 13 | +self.fib_array.append(1) |
14 | 14 | for i in range(2, N + 1):
|
15 |
| -self.fib_array[i] = self.fib_array[ |
16 |
| -i - 1] + self.fib_array[i - 2] |
17 |
| -else: |
18 |
| -self.fib_array = [None] * (N + 1) |
| 15 | +self.fib_array.append(self.fib_array[i - 1] + self.fib_array[i - 2]) |
| 16 | +elif N == 0: |
| 17 | +self.fib_array.append(0) |
19 | 18 |
|
20 | 19 | def get(self, sequence_no=None):
|
21 |
| -if sequence_no: |
| 20 | +if sequence_no != None: |
22 | 21 | if sequence_no < len(self.fib_array):
|
23 |
| -return print(self.fib_array[:sequence_no]) |
| 22 | +return print(self.fib_array[:sequence_no + 1]) |
24 | 23 | else:
|
25 | 24 | print("Out of bound.")
|
26 | 25 | else:
|
27 |
| -print("Please specify the a value") |
| 26 | +print("Please specify a value") |
28 | 27 |
|
29 | 28 |
|
30 | 29 | if __name__ == '__main__':
|
|
You can’t perform that action at this time.
0 commit comments