Question: Code is in Python: def LinearSearch(needle,haystack): return False #Do not make changes below this line. import random print(Welcome to Linear Search Test) x=input(Enter Seed to

Code is in Python:

def LinearSearch(needle,haystack):
return False
#Do not make changes below this line. import random print("Welcome to Linear Search Test") x=input("Enter Seed to Test: ") random.seed(x) target=random.randint(0,20) list=[random.randint(0,20) for x in range(0,10)] list.sort() print("Looking for",target) print("In list",list) x = LinearSearch(target,list) if x==True: print("Target was found.") else: print("Target was not found.") ![Seed to Test: ") random.seed(x) target=random.randint(0,20) list=[random.randint(0,20) for x in range(0,10)] list.sort()](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66e40f4f03fa8_15866e40f4e74bce.jpg)
2.4 Linear Search Complete the Python3 implementation of the Linear Search Algorithm given below. Each time you compare the needle to an element in the haystack, print out what you are comparing. Here is an example execution Welcome to Linear Search Test Enter Seed to Test: 12 Looking for 18 In list [0, 3, 4, 5, 9, 11, 13, 16, 18, 201 Comparing element o to needle 18 Comparing element 3 to needle 18 Comparing element 4 to needle 18 Comparing element 5 to needle 18 Comparing element 9 to needle 18 Comparing element 11 to needle 18 Comparing element 13 to needle 18 Comparing element 16 to needle 18 Comparing element 18 to needle 18 Target was found. The Pseudocode from lecture is given below as a guide. function LinearSearch (needle, haystack) for x=0; x needle then return false end if end for return false end function def LinearSearch(needle, haystack): return false #Do not make changes below this line. import random print("Welcome to Linear Search Test") x=input("Enter Seed to Test: ") random.seed(x) target=random.randint(0,20) list=[random.randint(0,20) for x in range(0,10)] list.sort() print("Looking for", target) print("In list", list) X = LinearSearch(target, list) if x==True: print("Target was found.") else: print("Target was not found.") Input 12 Your output Welcome to Linear Search Test Enter Seed to Test: Looking for 18 In list [0, 3, 4, 5, 9, 11, 13, 16, 18, 20] Target was not found. Expected output Welcome to Linear Search Test Enter Seed to Test: Looking for 18 In list [0, 3, 4, 5, 9, 11, 13, 16, 18, 20] Comparing element 0 to needle 184 Comparing element 3 to needle 184 Comparing element 4 to needle 184 Comparing element 5 to needle 184 Comparing element 9 to needle 184 Comparing element 11 to needle 18+ Comparing element 13 to needle 18+ Comparing element 16 to needle 18+ Comparing element 18 to needle 184 Target was found
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
