Computer Science

Define a function which accepts n as an argument and prints Fibonacci series till n.

Python

Python Modules

4 Likes

Answer

def print_fibonacci(n):
    a, b = 0, 1  
    while a <= n:
        print(a, end=' ')
        a, b = b, a + b  

n = int(input("Enter a number: "))
print_fibonacci(n)

Output

Enter a number: 10
0 1 1 2 3 5 8

Answered By

3 Likes


Related Questions