Skip to content

Conversation

yesIamHasi
Copy link
Contributor

This script contains python implementation of Fibonacci sequence in two forms.

  1. Formula Implementation.
  2. Iterative Implementation.
This script contains python implementation of Fibonacci sequence in two forms. 1) Formula Implementation. 2) Iterative Implementation.
@MrRishabhAnand
Copy link

#286 the code isn't correct

Copy link

@christianbender christianbender left a comment

Choose a reason for hiding this comment

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

Good Work! I have some requests.

class Fibonacci:
def formula(self, n):
'''Return nth fibonacci number using formula.'''
return int( ((1+sqrt(5))**n-(1-sqrt(5))**n)/(2**n*sqrt(5)) )

Choose a reason for hiding this comment

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

This line contains a bug. You must write in the head

from math import sqrt

for using the sqrt(...) function.

a,b = b, a+b
return b-a

def fibrange(self, start, stop, fast=True):

Choose a reason for hiding this comment

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

Use list compreshion

if not fast: fib_range = [self.iteration(i) for i in range(start,stop)] return fib_range else: fib_range = [self.formula(i) for i in range(start,stop)] return fib_range
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 participants