In this blog, we will discuss a list program, use of various methods, given below programs, asked in MNC companies and IPA assessment.

Problem Statement:

Create a list, get the input from the user list size and enter the element in the list, then search the element in or not in the list, search element is in the list to print the position of index or else to print search element is not found.

Program in Python:

def MySearch(s1,n,lst):
    flag=0
    for j in range(n):
        if lst[j]==s1:
            pos=j
            flag=1
    if flag:
        print("Position of search element index:",pos,sep='')
    else:
            print("Search element is not found!")

lst=[]
n=int(input("Enter the list size:"))
for i in range(n):
    ele=input()
    lst.append(ele)
print(lst)
search=input("Enter the search element:")
MySearch(search,n,lst)

Sample Output:

Enter the list size:5
Prabakaran S
21
India
Founder of Innovative Codes Academy
Thank you!
[‘Prabakaran S’, ’21’, ‘India’, ‘Founder of Innovative Codes Academy’, ‘Thank you!’]
Enter the search element:India
Position of search element index:2

Leave a Reply

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