Computer Science
Write a program that receives the index and returns the corresponding value.
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
Related Questions
What will be the output of the following code snippet?
Tup1 = ((1, 2),) * 7 print(len(Tup1[3:8]))
Write a Python program that creates a tuple storing first 9 terms of Fibonacci series.
Write a program that receives a Fibonacci term and returns a number telling which term it is. For instance, if you pass 3, it returns 5, telling it is 5th term; for 8, it returns 7.
Write a program to input n numbers from the user. Store these numbers in a tuple. Print the maximum and minimum number from this tuple.