Posts

Showing posts with the label fibonacci

Python program for Fibonacci series using Recursion

Image
What is the Fibonacci series The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on! Example: the next number in the sequence above is 21+34 =  55 code for Fibonacci series is terms = int(input("how many terms? : ")) #taking the input from the user #using recursion to print the series def recur_fibo(n,a1,a2): if n <= 1: #return this if terms is less than 1 print(a1) return else: print(str(a1) , end=" , ") return(recur_fibo(n-1,a2,a1 + a2)) #checking for the negative number and single terms if terms <= 0: print("Please enter a positive integer") elif terms == 1: print("Fibonacci Sequence of 1 terms : ") print(0) else: recur_fibo(terms,0,1) to veri