3rd_fibonacci_series

 n=int(input("Enter a number up to generate fibonacci series: "))

a=0
b=1
while a<n:
    print(a,end=" ")
    c=a+b
    a=b#the value of a is updated to be equal to the value of b
    b=c#the value of b is updated to be equal to the value of c
'''teration 1:
    a = 0
    b = 1
    Since 0 < 20, the condition is true.
    Output: 0

Iteration 2:
    a = 1
    b = 1
    Since 1 < 20, the condition is true.
    Output: 1

Iteration 3:
    a = 1
    b = 2
    Since 1 < 20, the condition is true.
    Output: 1

Iteration 4:
    a = 2
    b = 3
    Since 2 < 20, the condition is true.
    Output: 2

Iteration 5:
    a = 3
    b = 5
    Since 3 < 20, the condition is true.
    Output: 3

Iteration 6:
    a = 5
    b = 8
    Since 5 < 20, the condition is true.
    Output: 5

Iteration 7:
    a = 8
    b = 13
    Since 8 < 20, the condition is true.
    Output: 8

Iteration 8:
    a = 13
    b = 21
    Since 13 < 20, the condition is true.
    Output: 13

Iteration 9:
    a = 21
    b = 34
    Since 21 is not less than 20, the condition is false.'''

Comments

Popular posts from this blog

JAVA Lab Programs

HANGMAN GAME

WD 22. StylingLinks&Buttons