CBSE Class 12 Computer Science Question 101 of 105

Python Revision Tour II — Question 8

Back to all questions
8
Question

Question 8

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