Skip to content

Fixing some terms number issue, and improving result for first terms (0 and 1) #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 13, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions dynamic_programming/fibonacci.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@
class Fibonacci:

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, spaces before and after '=='

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget it, I'll add them

self.fib_array.append(0)

def get(self, sequence_no=None):
if sequence_no:
if sequence_no!=None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, spaces before and after '!='

if sequence_no < len(self.fib_array):
return print(self.fib_array[:sequence_no])
return print(self.fib_array[:sequence_no+1])
else:
print("Out of bound.")
else:
print("Please specify the a value")
print("Please specify a value")


if __name__ == '__main__':
Expand Down