Skip to content

Commit

Permalink
pep style and fixed exception on input other and integer type
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaysharma096 committed Sep 26, 2016
1 parent 7c90322 commit a3c5167
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions dynamic_programming/fibonacci.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""
This is a pure Python implementation of Dynamic Programming solution to the fibonacci sequence problem.
"""
class Fibonacci:


class Fibonacci:
def __init__(self, N=None):
if N:
N = int(N)
self.fib_array = [0] * (N + 1)
self.fib_array[0] = 0
self.fib_array[1] = 1
for i in range(2, N + 1):
self.fib_array[i] = self.fib_array[
i - 1] + self.fib_array[i - 2]
i - 1] + self.fib_array[i - 2]
else:
self.fib_array = [None] * (N + 1)

Expand Down Expand Up @@ -43,12 +45,13 @@ def get(self, sequence_no=None):
"\n********* Enter different values to get the corresponding fibonacci sequence, enter any negative number to exit. ************\n")
while True:
print("Enter value: ", end=" ")
i = eval(input())
if i < 0:
print("\n********* Good Bye!! ************\n")
break
fib.get(i)
except NameError:
print("\nInvalid input, please try again.")
try:
i = eval(input())
if i < 0:
print("\n********* Good Bye!! ************\n")
break
fib.get(i)
except NameError:
print("\nInvalid input, please try again.")
except NameError:
print("\n********* Invalid input, good bye!! ************\n")

0 comments on commit a3c5167

Please sign in to comment.