write a program in python to search an element present in a given list or not
Answers
Answer:
mylist = [12, 25, 35, 46, 5, 65, 77, 8] myinput = int(input("Type in a number ")) print("Number is in the list." if myinput in mylist else "Number not in list.") # or print("Number is in the list." if int(input("Type in a number ")) in mylist else "Number not in list.")
Answer:
This is the required Python program for the question.
n=int(input("How many elements?? "))
print("Enter them.. ")
l=[]
for i in range(n):
l.append(int(input(">> ")))
x=int(input("Enter the element to be searched for: "))
if x in l:
print("Element is in the list at index:",l.index(x))
else:
print("Not found.")
Here, we will ask the user to enter the elements in the list. After taking input, we will ask the user to enter the element to be searched for. If the element is present in the list, it displays the first index of that element with a message that the element is present in the list. An appropriate message will be displayed if the element is not found.
Refer to the attachment.
•••♪