Lesson 7: Fibonacci sequence

posted Nov 30, 2017, 8:00 AM by Attila Lengyel
fibonacci = []

fibonacci.append(0)
fibonacci.append(1)

print("Fibonacci sequence:", fibonacci)
print("Length:", len(fibonacci))

fibonacci.append(fibonacci[0] + fibonacci[1])

print("Fibonacci sequence:", fibonacci)
print("Length:", len(fibonacci))

for x in range (0,100):
  length = len(fibonacci)
  new = fibonacci[length - 1] + fibonacci[length - 2]
  fibonacci.append(new)

print("Fibonacci sequence:", fibonacci)
print("Length:", len(fibonacci))
 

Comments