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
Imagine that you are an independent filmmaker making a feature-length narrative film in the United States, with a variety of bot
Lerok [7]
Although an 8mm or 16mm would be better cost wise, I personally would use a 35 mm camera for this type of film. The 35mm is the only camera that would work well on a big screen. It is a rather expensive camera but no other camera could fit on the big screen.
7 0
3 years ago
Read 2 more answers
To stored three characters a computer occupies. Bytes memory space
klio [65]

Answer:

The computer represents all characters and numbers internally in the same fashion. In practice, memory is measured in KiloBytes (KB) or MegaBytes (MB).

Explanation:

The computer represents all characters and numbers internally in the same fashion. In practice, memory is measured in KiloBytes (KB) or MegaBytes (MB).

4 0
3 years ago
The key invention that enabled computers to go into every home and office is
Scrat [10]
<span><span />The Microprocessor is the key invention that enabled computers to go into every home and office. Microprocessor is a computer processor that enables the computer to run. It is also called as central processing unit. It is also a multipurpose and programmable device that accepts inputted data and process the data to provide an output. Microprocessor started from 8-bit design to 16bit, 32 bit, 64 bit and now it is produce a multi core design in the market. Faster and stronger design that can run heavier applications.</span>



8 0
4 years ago
Which federal legislation prohibits credit card companies from raising rates on existing balances?
Viefleur [7K]

Answer:

d

Explanation:

5 0
3 years ago
Read 2 more answers
What allows windows to quickly be resized by clicking the title bar of the window and dragging it to the top, sides, or middle o
ozzi

Answer: Snap

Explanation:Snapping is the technique in the computer field that helps in the positioning of the object or other component by the dragging motion. It works conveniently and the movement of dragging makes it easy.

The snapping works by the dragging the desktop, window or other component in sideways,top,vertically,middle, horizontally ,adjusting to the edges of desktop screen etc.

6 0
3 years ago
Other questions:
  • Number of byte required to store illumination
    13·1 answer
  • How do I decode this link? http://ambitiousadventurer.net/file.html?
    7·1 answer
  • When composing a tweet with images attached in hootsuite, bear in mind that _____ characters are used up by the photos?
    9·1 answer
  • Vhat is output by the code below?<br><br> PLEASE HELP!! TIME LIMIT!!
    5·1 answer
  • I don't understand how to write code for this in Java using nested for loops only. The official question is: write a program tha
    8·1 answer
  • What type of things can be marketed
    11·1 answer
  • The Internet Engineering Task Force (IETF) defines the protocols and standards for how the Internet works. The members of the IE
    12·1 answer
  • Helpppppppp!!!!!!!! Some program menus are the same in every program you open. Under the File menu, all of the following are the
    15·2 answers
  • Areas on which the development of the computer as a communication technology is based
    5·1 answer
  • Parameters and return make
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!