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 code to print fibonacci series 
Python :: python fibonacci sequence 
Python :: check the role of user in on_message discord.py 
Python :: start models 
Python :: pandas continues update csv 
Python :: how to move a specific row to last row in python 
Python :: scipy get frequencies of image 
Python :: user logout in django rest framework 
Python :: axes turn of axis matplotlb 
Python :: discord.py get user input (simplified) 
Python :: python date_end-date_Start in seconds 
Python :: who is agada nathan 
Python :: python last element of list using reverse() function 
Python :: mechanize python #8 
Python :: sklearn model persistence 
Python :: Local to ISO 8601 without microsecond: 
Python :: get_multiple_items_from_list 
Python :: AI code for diagnosing diseases 
Python :: # swap variables 
Python :: evaluacion PCA python 
Python :: average values in a list python 
Python :: give the factorials of 6 in python 
Python :: auto reload exml odoo 13 
Python :: Python String count() Implementation of the count() method using optional parameters 
Python :: numpy random sin 
Python :: python swap two numbers 
Python :: which can be reversed , string or list? 
Python :: fetch metric data from aws boto3 
Python :: Python NumPy moveaxis function Example 02 
Python :: data framing with Pandas 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =