1# Program to display the Fibonacci sequence up to n-th term
2
3nterms = int(input("How many terms? "))
4
5# first two terms
6n1, n2 = 0, 1
7count = 0
8
9# check if the number of terms is valid
10if nterms <= 0:
11 print("Please enter a positive integer")
12elif nterms == 1:
13 print("Fibonacci sequence upto",nterms,":")
14 print(n1)
15else:
16 print("Fibonacci sequence:")
17 while count < nterms:
18 print(n1)
19 nth = n1 + n2
20 # update values
21 n1 = n2
22 n2 = nth
23 count += 1