File tree 1 file changed +11
-7
lines changed
1 file changed +11
-7
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
+
5
+
4
6
class Fibonacci :
5
7
6
8
def __init__ (self , N = None ):
7
9
if N :
10
+ N = int (N )
8
11
self .fib_array = [0 ] * (N + 1 )
9
12
self .fib_array [0 ] = 0
10
13
self .fib_array [1 ] = 1
@@ -43,12 +46,13 @@ def get(self, sequence_no=None):
43
46
"\n ********* Enter different values to get the corresponding fibonacci sequence, enter any negative number to exit. ************\n " )
44
47
while True :
45
48
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." )
49
+ try :
50
+ i = eval (input ())
51
+ if i < 0 :
52
+ print ("\n ********* Good Bye!! ************\n " )
53
+ break
54
+ fib .get (i )
55
+ except NameError :
56
+ print ("\n Invalid input, please try again." )
53
57
except NameError :
54
58
print ("\n ********* Invalid input, good bye!! ************\n " )
You can’t perform that action at this time.
0 commit comments