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 :: python program to print the fibonacci sequence 
Python :: how to calculate fibonacci numbers in python 
Python :: what is a print statement 
Python :: tqdm in place 
Python :: skewness removal 
Python :: beautiful soap python get the link online 
Python :: create a virtualenv python3 
Python :: can you look for specific characters in python 
Python :: pandas count empty string values 
Python :: keras conv2d batchnorm 
Python :: get country from city python 
Python :: python string cut last character 
Python :: PY | websocket - server 
Python :: python string manipulation 
Python :: python inject into process 
Python :: how to have player input in python 
Python :: how to swap two variables without using third variable and default python functionality 
Python :: randint() 
Python :: queryset to list python 
Python :: reversed function python 
Python :: Set symmetric Using Python Set symmetric_difference() Method 
Python :: compare two datetime in python 
Python :: selenium undetected chromedriver error 
Python :: np.r_ 
Python :: pyjwt 
Python :: ipaddress in python 
Python :: fakultät python 
Python :: no module named googlesearch 
Python :: flask dockerize 
Python :: np reshape 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =