Write a recursive function that accepts an integer argument in n. This function returns the nth Fibonacci number. Call the function to print fibonacci sequences.

Source Code

def fib(n):
    if (n <= 0):
        return 0
    elif (n == 1):
        return 1
    else:
        return fib(n - 1) + fib(n - 2)


#calling the function to generate fibonacci sequence
print("The first 10 Fibonacci numbers are")

for x in range(10):
    print(fib(x),end=" ")

Output

The first 10 Fibonacci numbers are
0 1 1 2 3 5 8 13 21 34