Question #329082

Write a python function that takes the limit as an argument of the Fibonacci series and prints till

that limit.

===================================================================

Function Call:

fibonacci(10)

Output:

0 1 1 2 3 5 8

===================================================================

Function Call:

fibonacci(5)

Output:

0 1 1 2 3 5


Expert's answer

def fibonacci(n):
    fib=[0,1]
    print(fib[0], fib[1], sep=' ', end=' ')
    for i in range(2,n+1):
        fib.append(fib[i-1]+fib[i-2])
        if fib[i]<=n:
            print(fib[i], end=' ')
        else: break

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS