Fibonacci Sequence
Coding
first=0
second=1
n=int(input("Enter the number of terms"))
if(n<=0):
print("The series is ",first)
else:
print("The series is ",first,"",second,"",end="")
for i in range(2,n):
next=first+second
print(next,"",end="")
first=second
second=next
Output
The series is 0 1 1 2 3 5 8 13 21 34 (10 terms)
Comments
Post a Comment