Skip to content

Commit fb54d25

Browse files
committed
Linear Search
1 parent c825bb9 commit fb54d25

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

linear_search.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
nlist = [4, 2, 7, 5, 12, 54, 21, 64, 12, 32] #making a random list
2+
print('List has the items: ', nlist) #printing the items of the list
3+
searchItem = int(input('Enter a number to search for: ')) #asking for the number to be found among the shown list
4+
found = False
5+
for i in range(len(nlist)):
6+
if nlist[i] == searchItem:
7+
found = True
8+
print(searchItem, ' was found in the list at index ', i)
9+
break
10+
if found == False:
11+
print(searchItem, ' was not found in the list!')

0 commit comments

Comments
 (0)