Computer Science

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

Python

Python Tuples

27 Likes

Answer

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

Answered By

13 Likes


Related Questions