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
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
Comments
Leave a comment