Answer to Question #329082 in Python for ratul

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


1
Expert's answer
2022-04-15T08:23:11-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS