Python Program To Print Fibonacci Series | Advanced Coding

Python Program To Print Fibonacci Series

A Simple & Basic Python Program To Print Fibonacci Series using While Loop.

What is Fibonacci Series?
According to Wikipedia, In mathematics, the Fibonacci numbers, commonly denoted Fₙ, form a sequence, the Fibonacci sequence, in which each number is the sum of the two preceding ones. The sequence commonly starts from 0 and 1, although some authors start the sequence from 1 and 1 or sometimes from 1 and 2.

Python Program To Print Fibonacci Series

# Program To Print Fibonacci Series Upto nth Terms

nterms = int(input("Enter the total no. of terms: "))

#Set the first two terms

n1, n2 = 0, 1

increment = 0

#Check the values for nterms

if nterms <= 0:

  print("Please enter a positive value!")

elif nterms == 1:

  print("Fibonacci Series upto", nterms, ": ", n1)

else:

  print("Fibonacci Series upto", nterms, ": ")

  while increment < nterms:

  print(n1)

  new = n1 + n2

  #Update vales of n1 and n2

  n1 = n2

  n2 = new

  increment += 1

OUTPUT: 

Enter the total no. of terms: 10

Fibonacci Series Upto 10: 

0

1

1

2

3

5

8

13

21

34

IDE used in the tutorial – SPYDER

Check the video tutorial here:

Thank You

Leave a Comment