39 - Write a program in Python to Input a tuple of numbers and find the index of a specific element.
T= (5, 8, 9, 2, 6)
print("Tuple is : ",T)
c='Y'
while c=='Y' or c=='y':
n=int(input("Enter the number to be search in the tuple: "))
found=False
for i in T:
if i==n:
print("Element found at index: ",T.index(i))
found=True
if found==False:
print("Number is not found in the tuple")
c=input("Do you want to search more item (Y/N): ")
Output:
Tuple is : (5, 8, 9, 2, 6)
Enter the number to be search in the tuple: 8
Element found at index: 1
Do you want to search more item (Y/N): y
Enter the number to be search in the tuple: 2
Element found at index: 3
Do you want to search more item (Y/N): y
Enter the number to be search in the tuple: 7
Number is not found in the tuple
Do you want to search more item (Y/N): n
No comments:
Post a Comment