Fibonacci Series Program in Python
Advertisements
Fibonacci Series Program in Python
You can write this program using for loop and while loop. Follow same concept like C programming only change syntax.
Fibonacci Series Program in Python
def fun(n):
"""Recursive function to
print Fibonacci sequence"""
if n <= 1:
return n
else:
return(fun(n-1) + fun(n-2))
# receive input from the user
terms = int(input("How many terms U want Fibonacci ?: "))
if terms <= 0:
print("Plese enter only positive integer")
else:
print("Fibonacci Series:")
for i in range(terms):
print(fun(i))
Output
How many terms U want Fibonacci ?: 10 Fibonacci Series: 0 1 1 2 3 5 8 13 21 34
Google Advertisment
