1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mazyrski [523]
3 years ago
13

The find_item functions uses binary search to recursively locate an item is the list, returning true if found, false otherwise.

Something is missing from this function. Can you spot what it is and fix it. Add debug lines where appropriate, to help narrow the problem.
Computers and Technology
1 answer:
bagirrra123 [75]3 years ago
7 0

Answer:

def find_item(listed, item):

   listed.sort()

   #Returns True if the item is in the list, False if not.

   if len(listed) == 0:

       return False

   middle = int(len(listed)/2)

   #Is the item in the first half of the list?

   if item < listed[middle]:

   #Call the function with the first half of the list

       return find_item(listed[:middle], item)

   

   #Is the item in the center of the list?

   if listed[middle] == item:

       return True

   else:

   #Call the function with the second half of the list

       return find_item(listed[middle+1:], item)

   return False

list_of_names = ["Parker", "Drew", "Cameron", "Logan", "Alex", "Chris", "Terry", "Jamie", "Jordan", "Taylor"]

print(find_item(list_of_names, "Alex")) # True

print(find_item(list_of_names, "Andrew")) # False

print(find_item(list_of_names, "Drew")) # True

print(find_item(list_of_names, "Jared")) # False

Explanation:

The defined python function is used to implement a binary search, the function is recursively called in the function statement, but for it to work on the list ( ie, search for an item in the list), the list must be sorted in ascending order (default).

You might be interested in
4.9 Code Practice: Question 2
agasfer [191]

total = 0

for x in range(20, 91, 10):

   total += x

   print(total)

I hope this helps!

7 0
3 years ago
Read 2 more answers
3.4 lesson practice
Strike441 [17]

Answer:

The answer is A. Second Half of the month.

Explanation:

If Im reffering right to the source. So If you doing Chapter 3 Comp. Science. Than this is right.

7 0
3 years ago
Read 2 more answers
Which form of online communication happens in real time?
son4ous [18]

Answer:

texting? it happens in real time and is online.

5 0
2 years ago
Please help me with computing!
Sladkaya [172]

Answer:

ok i help

Explanation:

3 0
3 years ago
Which statement best describes top-down programming design?
MariettaO [177]

B is the answer (i think)

5 0
3 years ago
Other questions:
  • ____ allows someone browsing the internet to click on words or phrases, enter his or her phone number, and continue browsing
    11·2 answers
  • A short circuit locator should be periodically run along the cords used in a shop to check for shorts and open circuits. A.)True
    12·2 answers
  • Why should a person consider doing an apprenticeship?
    7·1 answer
  • Write the simplest statement that prints the following on a single line: 3 2 1 Go! Note: Whitespace (blank spaces / blank lines)
    11·1 answer
  • Plssss helpppp!!<br><br>Thanks
    11·2 answers
  • Which applications run on IHGs private cloud?
    13·1 answer
  • If you could pick xbox or playstation what would you pick?And why :)?
    11·2 answers
  • What is the purpose of using variables in programming?
    11·1 answer
  • Which of these exemplifies an iterative process
    15·2 answers
  • In addition to environmental issues, what does true sustainability address?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!