Program to print Fibonacci series in python
The Fibonacci numbers, commonly refers as Fibonacci sequence, in which each number is the sum of the two preceding numbers, starting from 0 and 1.
The Fibonacci Sequence is the series of numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …
# Program to print Fibonacci sequence for 7 numbers #fibonacci.py terms = 7 n1, n2 = 0, 1 count = 0 if terms <= 0: print ("Please enter positive term") elif terms == 1 : print(n1,n2) else: while terms > count: print(n1) nth = n1 + n2 n1 = n2 n2 = nth count +=1
Output:
$ python fibonacci.py 0 1 1 2 3 5 8
(Visited 315 times, 1 visits today)