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
From where do we get information or knowledge? Explain.
Tems11 [23]

Answer:

the explanations is down here,

Explanation:

Information

Data reaches a more complex level and becomes information by integrating them to a context. Information provides expertise about facts or persons. Example of information: The information about a date of birth still has very little value when it is unknown to which person it belongs. By adding more information like the name, the linked information creates knowledge about a person.

Knowledge

Knowledge thus describes the collected information that is available about a particular fact or a person. The knowledge of this situation makes it possible to make informed decisions and solve problems. Thus, knowledge influences the thinking and actions of people. Machines can also make decisions based on new knowledge generated by information. In order to gain knowledge, it is necessary to process information.

7 0
3 years ago
Read 2 more answers
Write a program that will add up the series of numbers: 99, 98, 97… 3, 2, 1. The program should print the running total as well
Elanso [62]

Answer:

a = 99

b = 99

while(a > 0):

    b += a

    print(b)

    a -= 1

Explanation:

4 0
3 years ago
What will be returned when the following SQL statement is executed?
ycow [4]

Answer:

b) A listing of each driver as well as the number of deliveries that he or she has made

Explanation:

SQL which stands for Structured Query Language. and an SQL statements are used in performing tasks such as to update data on a database, or retrieve data from a database. Some of the popular relational database management systems that use SQL are: Sybase, Oracle, Microsoft SQL Server, Ingres, Access, etc.

3 0
3 years ago
Read 2 more answers
What is the name of a button on a website?
zhuklara [117]
May I know which button?
5 0
3 years ago
Create an absolute value component abs() with an 8-bit input A that is a signed binary number, and an 8-bit output Q that is uns
Stolb23 [73]

Answer:

Explanation:

Find attached the solution

5 0
3 years ago
Other questions:
  • Ethan wants to change the font in his document. He should _____.
    8·2 answers
  • Which device assists with medical imaging? HELPPPP!!!!!!
    12·1 answer
  • Que son los sistemas de control con retroalimentacion
    10·1 answer
  • Write a C program that includes a function of type double called divemaster accepts two double arguments (you must write the div
    15·1 answer
  • What is the square root of 1600 and 36 ?​
    6·1 answer
  • Which of the following would be useful to understand if you wanted to build a web page
    15·1 answer
  • In which drawer can you set certain lights to light up on your micro:bit?
    12·2 answers
  • A brick has a weight of 23N. The brick is flat and smooth on the side in contact with the floor having measurements ( height= 5c
    13·1 answer
  • Question 1 of 10
    13·1 answer
  • For a certain company, the cost function for producing x items is C(x)=50x+100 and the revenue function for selling x items is R
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!