File tree 1 file changed +12
-9
lines changed
1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
2
This is a pure Python implementation of Dynamic Programming solution to the fibonacci sequence problem.
3
3
"""
4
- class Fibonacci :
5
4
5
+
6
+ class Fibonacci :
6
7
def __init__ (self , N = None ):
7
8
if N :
9
+ N = int (N )
8
10
self .fib_array = [0 ] * (N + 1 )
9
11
self .fib_array [0 ] = 0
10
12
self .fib_array [1 ] = 1
11
13
for i in range (2 , N + 1 ):
12
14
self .fib_array [i ] = self .fib_array [
13
- i - 1 ] + self .fib_array [i - 2 ]
15
+ i - 1 ] + self .fib_array [i - 2 ]
14
16
else :
15
17
self .fib_array = [None ] * (N + 1 )
16
18
@@ -43,12 +45,13 @@ def get(self, sequence_no=None):
43
45
"\n ********* Enter different values to get the corresponding fibonacci sequence, enter any negative number to exit. ************\n " )
44
46
while True :
45
47
print ("Enter value: " , end = " " )
46
- i = eval (input ())
47
- if i < 0 :
48
- print ("\n ********* Good Bye!! ************\n " )
49
- break
50
- fib .get (i )
51
- except NameError :
52
- print ("\n Invalid input, please try again." )
48
+ try :
49
+ i = eval (input ())
50
+ if i < 0 :
51
+ print ("\n ********* Good Bye!! ************\n " )
52
+ break
53
+ fib .get (i )
54
+ except NameError :
55
+ print ("\n Invalid input, please try again." )
53
56
except NameError :
54
57
print ("\n ********* Invalid input, good bye!! ************\n " )
You can’t perform that action at this time.
0 commit comments