Python program to generate a Fibonacci series using recursion
def
fibonacci(n):
if n<=1:
return n
else:
return fibonacci(n-1)+fibonacci(n-2)
no_of_terms=int(input("enter
the no.of terms"))
if
no_of_terms<=0:
print("please enter a positive
integer")
else:
print("fibonacci sequence is:")
for k in range(no_of_terms):
print(fibonacci(k))
Output:
enter the no.of terms7
fibonacci sequence is:
0
1
1
2
3
5
8
Regards:
Trilochan Tarai
Silan Technology, BBSR
Call Us : 0674-2361252
Our Services:
JAVA Training || Python
Training || DataScience with Python Training ||
Machine Learning with Python Training
|| Projects
Comments
Post a Comment