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 formula python 
Python :: fibonacci sequence python code 
Python :: fibonacci using function in python 
Python :: create a fibonacci function using a generator python 
Python :: check the role of user in on_message discord.py 
Python :: when was python 3 released 
Python :: get the values of your aws tags from ec2 instance 
Python :: add vertical line to horizontal graph 
Python :: python min function time complexity 
Python :: get all methods of an instance 
Python :: operations in python 
Python :: qtoverlay 
Python :: python youtube_dl custom path 
Python :: how to make a series in python alternating between + and - 
Python :: mechanize python XE #29 
Python :: factorial python 
Python :: how to run function when file is modified python 
Python :: torch remove part of array 
Python :: read(stdin, buf) ctf 
Python :: python access class property from string 
Python :: Doubleclick .py Prep 
Python :: separating numeric and categorical feature using loop 
Python :: how-to-add-new-column-to-an-dataframe-to-the-front-not-end 
Python :: Find Factors of a Number Using Class 
Python :: matplotlib pie turn small pct labels off 
Python :: linear search algorithm python 
Python :: python convert dataframe target to numbers 
Python :: ouvrir fichier txt python et le lire 
Python :: Python NumPy atleast_3d Function Syntax 
Python :: how to make dinamic table in jinja python 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =