Question
To Print the Fibonacci Series.
Sample TestCaseExpected Output
How many numbers? 5 Fibonacci Series
0
1
1
2
3
Answer
nterms=int(input("How many terms ? "))
n1,n2=0,1
count=0
if nterms<=0:
print("Enter a Positive Integer")
elif nterms==1:
print("Fibonacci Series")
print(n1)
else:
print("Fibonacci Series")
while count<nterms:
print(n1)
nth=n1+n2
n1=n2
n2=nth
count+=1

No comments:
Post a Comment