ProgrammingHardCodeforces-style · placement coding round

What is printed?

What is printed?
def find(g, t):
    for i, row in enumerate(g):
        for j, v in enumerate(row):
            if v == t:
                break
        else:
            continue
        return (i, j)
    return None
print(find([[1, 2], [3, 4]], 3), find([[1, 2], [3, 4]], 9))
  1. A. (1, 0) None
  2. B. (1, 1) None
  3. C. (0, 0) None
  4. D. (1, 0) (1, 1)

Correct answer: A. (1, 0) None

The inner break skips its else clause, so the function returns the position where the value was found. The outer loop's else with continue handles rows that have no match.

More Python Programming questions

Exams that ask this topic