Repair the complete search behavior

A programmer intends this Python function to return the first matching zero-based index, or -1 if the target is absent. Examine its behavior for empty lists, last-element matches, and duplicates. Which statements are true? Select all that apply.


Python
def locate(values, target):
    result = -1
    for i in range(len(values) - 1):
        if values[i] == target:
            result = i
    return result
Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Sequential Search Questions: