Aim:

To write a Python Program to perform Linear Search

Algorithm:

1. Read n elements into the list

2. Read the element to be searched

3. If alist[pos]==item, then print the position of the item

4. else increment the position and repeat step 3 until pos reaches the length of the list

Program:

items = [5, 7, 10, 12, 15]

print("list of items is", items)

x = int(input("enter item to search:")

i = flag = 0

while i < len(items):

if items[i] == x:

flag = 1

break

i = i + 1

if flag == 1:

print("item found at position:", i + 1)

else:

print("item not found")

Sample Output:

$python main.py (list of items is: [5, 7, 10, 12, 15] )

 enter item to search: 7 (item found at position:, 2)