mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-19 00:37:02 +00:00
pep style and fixed exception on input other and integer type
This commit is contained in:
parent
7c90322815
commit
a3c5167fad
|
@ -1,16 +1,18 @@
|
||||||
"""
|
"""
|
||||||
This is a pure Python implementation of Dynamic Programming solution to the fibonacci sequence problem.
|
This is a pure Python implementation of Dynamic Programming solution to the fibonacci sequence problem.
|
||||||
"""
|
"""
|
||||||
class Fibonacci:
|
|
||||||
|
|
||||||
|
|
||||||
|
class Fibonacci:
|
||||||
def __init__(self, N=None):
|
def __init__(self, N=None):
|
||||||
if N:
|
if N:
|
||||||
|
N = int(N)
|
||||||
self.fib_array = [0] * (N + 1)
|
self.fib_array = [0] * (N + 1)
|
||||||
self.fib_array[0] = 0
|
self.fib_array[0] = 0
|
||||||
self.fib_array[1] = 1
|
self.fib_array[1] = 1
|
||||||
for i in range(2, N + 1):
|
for i in range(2, N + 1):
|
||||||
self.fib_array[i] = self.fib_array[
|
self.fib_array[i] = self.fib_array[
|
||||||
i - 1] + self.fib_array[i - 2]
|
i - 1] + self.fib_array[i - 2]
|
||||||
else:
|
else:
|
||||||
self.fib_array = [None] * (N + 1)
|
self.fib_array = [None] * (N + 1)
|
||||||
|
|
||||||
|
@ -43,12 +45,13 @@ if __name__ == '__main__':
|
||||||
"\n********* Enter different values to get the corresponding fibonacci sequence, enter any negative number to exit. ************\n")
|
"\n********* Enter different values to get the corresponding fibonacci sequence, enter any negative number to exit. ************\n")
|
||||||
while True:
|
while True:
|
||||||
print("Enter value: ", end=" ")
|
print("Enter value: ", end=" ")
|
||||||
i = eval(input())
|
try:
|
||||||
if i < 0:
|
i = eval(input())
|
||||||
print("\n********* Good Bye!! ************\n")
|
if i < 0:
|
||||||
break
|
print("\n********* Good Bye!! ************\n")
|
||||||
fib.get(i)
|
break
|
||||||
except NameError:
|
fib.get(i)
|
||||||
print("\nInvalid input, please try again.")
|
except NameError:
|
||||||
|
print("\nInvalid input, please try again.")
|
||||||
except NameError:
|
except NameError:
|
||||||
print("\n********* Invalid input, good bye!! ************\n")
|
print("\n********* Invalid input, good bye!! ************\n")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user