CBSE Class 11 Computer Science Question 98 of 114

Tuples — Question 1

Back to all questions
1
Question

Question 1

Write a Python program that creates a tuple storing first 9 terms of Fibonacci series.

Solution
lst = [0,1]
a = 0
b = 1
c = 0

for i in range(7):
    c = a + b
    a = b
    b = c
    lst.append(c)

tup = tuple(lst)

print("9 terms of Fibonacci series are:", tup)
Output
9 terms of Fibonacci series are:  (0, 1, 1, 2, 3, 5, 8, 13, 21)
Answer