Python program for Fibonacci series using Recursion

What is the Fibonacci series

fibonacci_logo


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 verify the indentation of the program screenshot of the program is 

program_fibonacci


Output for this program is 

output_fibonacci
output

Thanks for being here.
Any problem or suggestion please comment below.

Comments

Popular posts from this blog

Bubble sort in Python Language

Third Equation of motion, How to implement using C language

Top 5 Programming language need to learn in 2020