+ 2

Write a program to search for an element in a given list of number

30th Sep 2019, 1:27 PM
Ayush Tripathi
Ayush Tripathi - avatar
2 Answers
+ 7
lst=eval(input(“Enter list:”)) length=len(lst) element=int(input(“Enter element to be searched for:”)) for i in range(0,length): if element==lst[i]: print(element,”found at index”,i) break else: print(element,”not found in given list”)
30th Sep 2019, 1:55 PM
Mohamed Arshad
Mohamed Arshad - avatar
+ 2
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.")
30th Sep 2019, 5:43 PM
rodwynnejones
rodwynnejones - avatar