-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinearSearch.py
More file actions
36 lines (26 loc) · 925 Bytes
/
LinearSearch.py
File metadata and controls
36 lines (26 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from Item import Item
items = [Item("Cooking Book", 18, 100),
Item("Recipies", 33, 200),
Item("Pen", 4, 1002),
Item("Pencil", 2, 123),
Item("Blackboard", 70, 89),
Item("Recipi Book", 18, 100),
Item("Gardening", 33, 200),
Item("Table top", 4, 1002),
Item("Plant", 2, 123),
Item("Whiteboard", 70, 89)]
def LinearSearch(items, item_name_to_search):
item_to_search = Item(item_name_to_search, 0, 1)
for i in range(len(items)):
if items[i] == item_to_search:
return items[i]
return None
while(True):
item_found = LinearSearch(items, input("Enter the item name you want to check: "))
if item_found == None:
print("Item was not found")
else:
print(f"Found item:\n{item_found}")
choice = input("Do you wish to continue? Press Y or N: ")
if choice != 'Y':
break;