File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change 11"""
22This is a pure Python implementation of Dynamic Programming solution to the fibonacci sequence problem.
33"""
4- class Fibonacci :
54
5+
6+ class Fibonacci :
67 def __init__ (self , N = None ):
78 if N :
9+ N = int (N )
810 self .fib_array = [0 ] * (N + 1 )
911 self .fib_array [0 ] = 0
1012 self .fib_array [1 ] = 1
1113 for i in range (2 , N + 1 ):
1214 self .fib_array [i ] = self .fib_array [
13- i - 1 ] + self .fib_array [i - 2 ]
15+ i - 1 ] + self .fib_array [i - 2 ]
1416 else :
1517 self .fib_array = [None ] * (N + 1 )
1618
@@ -43,12 +45,13 @@ def get(self, sequence_no=None):
4345 "\n ********* Enter different values to get the corresponding fibonacci sequence, enter any negative number to exit. ************\n " )
4446 while True :
4547 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." )
5356 except NameError :
5457 print ("\n ********* Invalid input, good bye!! ************\n " )
You can’t perform that action at this time.
0 commit comments