Input a list/tuple of elements and search for a given element in the list/tuple Python Program

Input a list/tuple of elements and search for a given element in the list/tuple Python Program

 

# Python Program to input a list of 5 elements and search element in List

 

mylist = []

print("Enter 5 elements for the list: ")

for i in range(5):

    value = int(input())

    mylist.append(value)

print("Enter an element to be search: ")

element = int(input())

for i in range(5):

    if element == mylist[i]:

        print("\nElement found at Index:", i)

        print("Element found at Position:", i+1)

 

Output:

Enter 5 elements for the list: 
45
34
37
34
55
Enter an element to be search: 
34
('\nElement found at Index:', 1)
('Element found at Position:', 2)
('\nElement found at Index:', 3)
('Element found at Position:', 4)
>>> 



You may also Check :

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *