from time import sleep
fibonacci = [1,1]
while True:
first = fibonacci[-2]
second = fibonacci[-1]
sum = first + second
fibonacci.append(int(sum))
print(sum)
sleep(0.05)
In this code, I want to show you 2 ways of coding the Fibonacci sequence in python. 1 way is as shown above which I intend to use to also teach you list indexing or the shorter way below which makes use of recursion:
def Fibonacci(x,y):
print(x+y)
Fibonacci(x+y,x)
Fibonacci(1,1)
#computer-science #coding #programming #python #fibonacci