Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

fibonacci sequence in python using whileloop

# Program to display the Fibonacci sequence up to n-th term

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

# first two terms
n1, n2 = 0, 1
count = 0

# check if the number of terms is valid
if nterms <= 0:
   print("Please enter a positive integer")
# if there is only one term, return n1
elif nterms == 1:
   print("Fibonacci sequence upto",nterms,":")
   print(n1)
# generate fibonacci sequence
else:
   print("Fibonacci sequence:")
   while count < nterms:
       print(n1)
       nth = n1 + n2
       # update values
       n1 = n2
       n2 = nth
       count += 1
Comment

PREVIOUS NEXT
Code Example
Python :: fibonacci program in python 
Python :: fibonacci sequence script python 
Python :: python code for fibonacci 
Python :: how to do fibonacci sequence in python 
Python :: copy any files from one folder to another folder in python 
Python :: code.org void loops 
Python :: fake-useragent proxy webscraping browser change 
Python :: atan of number python 
Python :: using default as none in django mdoels 
Python :: how to do downsampling in python 
Python :: how to add another timestamp column plus two hours 
Python :: disable network on pytest 
Python :: fastapi authentication 
Python :: python paragraph Pypi 
Python :: step out pdb python 
Python :: form list of filename get the filename with highest num pythn 
Python :: unpack 
Python :: python clean filename 
Python :: time vs timeit 
Python :: # generators 
Python :: turn of legend pairplot 
Python :: R[~i] in python 
Python :: python is not defined 
Python :: Code Example of Checking if a variable is None using == operator 
Python :: matplotlib 3d plot angle 
Python :: Using **kwargs to pass the variable keyword arguments to the function 
Python :: how to move mouse by detected face and eye using opencv 
Python :: install python 3.10 pip 
Python :: Python NumPy atleast_3d Function Example 2 
Python :: youtube-dl python not found 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =