Program to print the Fibonacci Series
What is fibonacci series?
Fibonacci series are a sequence of fibonacci numbers such that each number is the sum of the two preceding ones, starting from 0 and 1. That is, and for n > 1. The sequence starts:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89...
#0,1, 1, 2, 3 ,5
print("1. Print the nth term of the fibonacci series")
print("2. Print till the nth term of the fibonacci series")
choice=int(input("Enter your choice, 1 or 2: "))
if choice==1: #print the nth term of the fibonacci series
n=int(input("Enter the term "))
f,s=0,1
c=0
for i in range(2,n):
c=f+s
f,s=s,c
print(c)
elif choice==2: #print till the nth term of the fibonacci series
n=int(input("Enter the nth term "))
f,s=0,1
c=0
print(f)
print(s)
for i in range(2,n):
c=f+s
f,s=s,c
print(c)
else:
print("Enter 1 or 2")
Comments
Post a Comment