Tests that miss a largest-value bug

The Python function below is meant to return the largest number in a non-empty list. It contains no syntax errors and never crashes on lists of numbers.


Python
def largest(values):
    best = 0
    for v in values:
        if v > best:
            best = v
    return best


A tester runs it on the four input lists in the table. For each list, enter the value the function actually returns, the true largest value in the list, and whether the two match (type yes or no).

Input valuesValue returnedTrue largest valueMatch (yes or no)
3, 8, 5
-4, -2, -9
-6, 0, -1
2, -7, 1

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 Bug Types (Syntax, Runtime, Logic) Questions: