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
When inserting a fly in animation what is the first step in the process?
weqwewe [10]

Answer:

you select the element you wish to animate

6 0
3 years ago
A characteristic often associated with entrepreneurship is
FromTheMoon [43]

Answer:

with small businesses

Explanation:

to make a lager profit

3 0
3 years ago
True or false a weighted inventory system is often tied into player advancement
alekssr [168]

Answer:tayfana

Explanation:true

7 0
2 years ago
This standard library function returns a random floating-point number in the range of 0.0 up to 1.0 (but not including 1.0).
natulia [17]

Answer:

The answer would be A: Random

Explanation:

The random() function returns a generated random number (a pseudorandom number)

5 0
2 years ago
Place the steps in order for inserting an index in a document.
tester [92]

Answer:

Steps to insert an index in a document

Explanation:

  1. open the document
  2. click on the <u>references</u> tab either above or below the document
  3. click the <u>mark entry</u> button
  4. select a word or group of words for the index
  5. click on the <u>mark entry</u> dialogue box
  6. format the page numbers in your index
  7. format the text for your index entry
  8. click <u>mark</u>
  9. click <u>mark all</u>
7 0
3 years ago
Read 2 more answers
Other questions:
  • Which features would work well for text entered into cells? Check all that apply.
    5·2 answers
  • e do loop differs from the while loop in that a. the while loop will always execute the body of the loop at least once b. the do
    9·1 answer
  • Which of the following does not use a Graphic User Interface?
    14·1 answer
  • When entering data in Access if the data is entered using an Access form, that data is stored in a table or tables. TRUE FALSE
    12·1 answer
  • do you think that some people have difficulty talking to others face to face because of how prevalent texting is today
    15·2 answers
  • Explain how the CPU processes data instructions.
    6·1 answer
  • An office uses an application to assign work to its staff members. The application uses a binary sequence to represent each of 1
    9·1 answer
  • C#
    10·1 answer
  • A new user needs access to their files in iCloud without relying on the operating system (OS). How would the user access the App
    13·1 answer
  • If any one has mincraft on ps4 bedrock we can finish building a BIG city world all we need to put is a shop and money dispensers
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!