You are on page 1of 2

0,1,1,2,3,5,8,13,21………..

n
n=int(input("Enter the no of terms"))
n1,n2=0,1
i=1
print("The Fibonacci Series is")
while i<=n:
print(n1)
temp=n1+n2
n1=n2
n2=temp
i=i+1 Output:0,1,1

Tracing:
n=6
n1=0
n2=1
i=1

1st iteration
temp=0+1=1
n1=1
n2=1
i=2

2nd iteration
temp=1+1=2
n1=1
n2=2
i=2+1=3

3rd iteration
temp=3
n1=2
n2=3
i=4

4th iteration
temp=5
n1=3
n2=5
i=5

5th iteration
temp=8
n1=5
n2=8
i=6

6th iteration
temp=13
n1=8
n2=13
i=7

You might also like