Skip to content

Commit 6a68559

Browse files
authored
Merge pull request TheAlgorithms#32 from akshaysharma096/master
PEP style and fixed exception on input other and integer type
2 parents f9a69ee + 2dcb85d commit 6a68559

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

dynamic_programming/fibonacci.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
"""
22
This is a pure Python implementation of Dynamic Programming solution to the fibonacci sequence problem.
33
"""
4+
5+
46
class Fibonacci:
57

68
def __init__(self, N=None):
79
if N:
10+
N = int(N)
811
self.fib_array = [0] * (N + 1)
912
self.fib_array[0] = 0
1013
self.fib_array[1] = 1
@@ -43,12 +46,13 @@ def get(self, sequence_no=None):
4346
"\n********* Enter different values to get the corresponding fibonacci sequence, enter any negative number to exit. ************\n")
4447
while True:
4548
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("\nInvalid 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("\nInvalid input, please try again.")
5357
except NameError:
5458
print("\n********* Invalid input, good bye!! ************\n")

0 commit comments

Comments
 (0)