Saturday, October 24, 2020

How to create Fibonacci Sequence in Python

Code:

nTerms = int( input( "How many terms?" ))

n1, n2 = 0, 1
count = 0


if nTerms <= 0:
        print ("Please enter a positive integer")

elif nTerms == 1:
        print (n1)

else:
        while count < nTerms:
                print(n1)
                nth = n1 + n2
                
                n1 = n2
                n2 = nth
                count += 1