Answers for "Fib"

0

Fib

'''
Since the fibbonacci sequence is the same whether it begins with 1,1 or 0,1,
it doesn't affect the sequence whether you say it begins with a 0 or 1.
Having said that when describing the nth term of the sequence it is usually taken that the first term is 1,
the second term is 1, the zeroth term is 0, the -1th term is 1, the -2th term is -1 and so on in both directions like that.
It doesn't exactly have a definite start since it can be worked infinitely in reverse, but when referring to the first term we say that the first
'''
 
def fib(n):
    a, b = 0, 1
    for _ in range(n):
        yield a
        a, b = b, a + b
 
print(list(fib(10)))
Posted by: Guest on May-15-2021

Browse Popular Code Answers by Language