Python Program to Find nth Fibonacci number


Using function

In [1]:
def fibonacci(n):
    if(n <= 0):
        print("Invalid Input.")
    elif(n ==1 or n==2):
        return n - 1
    else:
        return fibonacci(n-1) + fibonacci(n-2)

number = int(input("Please enter the number:"))
print("Fibonacci number =",fibonacci(number))
Please enter the number:8
Fibonacci number = 13

In this program, we will create a recursive function to generate the nth Fibonacci number.