Question: nterms = int ( input ( How many terms? ) ) # first two terms n 1 , n 2 = 0 ,

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
# update values
n1= n2
#correction is here
n2= nth+n1
count +=1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!