Header Ads Widget

Write a python program for linear search.

What is linear searching:-

Linear searching is a searching algorithm in which we search the elements linearly .  we compare the element with all the elements and if elements is found in the list then break the loop and print element is present in the list.  

 Code:-


print("Enter the list of the number")
mylist=list(map(int,input().split()))
num=int(input("Enter the number for searching"))
for i in mylist:
if i==num:
print("Value is in the list")
break
else:
print("Value is not in the list")


Output:-


Enter the list of the number
12 23 43 54 67 8
Enter the number for searching 12
Value is in the list

Recommended Post:-

         MCQs:-