Python program to generate Fibonacci series




Fibonacci Series

                         Hello friends, In this post we see the python code to generate Fibonacci series. Fibonacci series means if we are giving input as 7 then the output is 0  1  1  2  3  5.
                        Means in output first digit is 0 then second is 1,addition of first and second digit is third digit i.e.0+1=1,next is 1+1=2,then 2+1=3,then 3+2=5. The next digit is 5+3=8 but 8 is greater than 7(8>7) i.e.(8!<7) so the control is transfer to the out of the loop. The actual code is as follows:
Program:

n=int(input('Enter the number:'))
a=0
b=1
c=a+b
print("fibonacci series is :")
while(c<=n):
      print(c)
      a=b
      b=c
      c=a+b

Output:
Enter the number:48
Fibonacci series is :
1
2
3
5
8
13
21
34
>>>










Python program to generate Fibonacci series Python program to generate Fibonacci series Reviewed by Amit Waghmare on November 11, 2019 Rating: 5

No comments: