n = int(input("Enter the number of terms: "))
# initialize the first two terms of the sequence
a, b = 0, 1
# check if the number of terms is valid
if n <= 0:
print("Please enter a positive integer")
elif n == 1:
print("Fibonacci sequence up to", n, "term:")
print(a)
else:
print("Fibonacci sequence up to", n, "terms:")
for i in range(n):
print(a, end=' ')
c = a + b
a = b
b = cEnter the number of terms: 15
Fibonacci sequence up to 15 terms:
> 15
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 150` and `1`. 0`. n` terms of the Fibonacci sequence by adding the previous two terms.