CBSE Class 11 Computer Science Question 99 of 114

Tuples — Question 2

Back to all questions
2
Question

Question 2(a)

Write a program that receives the index and returns the corresponding value.

Solution
tup = eval(input("Enter the elements of tuple:"))
b = int(eval(input("Enter the index value:")))
c = len(tup)

if b < c:
    print("value of tuple at index", b ,"is:" ,tup[b])
else:
    print("Index is out of range")
Output
Enter the elements of tuple: 1,2,3,4,5
Enter the index value: 3
value of tuple at index  3  is:  4
Answer