Fibonacci Number Using Recursion Method

Fibonacci series is a series of numbers formed by the addition of the
preceeding two numbers in the series.

Examples of Fibonacci Series: 0+1+1+2+3+5....
0 and 1 are the first two terms of the series. These two terms are printed directly. The third term is calculated by adding the first two terms. In this case 0 and 1. So, we get 0+1=1. Hence 1 is printed as the third term. The next term is generated by using the second and third term and not using the first term.

n=int(input("Enter the Number:" ))
def Fib(n):

    if n==1:
        return 0
    elif n==2:
        return 1
    elif n<=0:
        return ("Invalid")
    else:
        return(Fib(n-1)+Fib(n-2))
        
print("Fibonacci Number of",n,"is :",Fib(n))



If you have any doubts, feel free to post it in comment Section.

Comments

Popular posts from this blog

Guessing the Number Game

Find the final amount after Discount

Simple Arithmetic Calculator - User Defined Function