ProgrammingModerateTCS NQT · Accenture

What is printed?

What is printed?
import itertools
print(sum(b - a for a, b in itertools.pairwise([1, 4, 2, 8])))
  1. A. 7
  2. B. 11
  3. C. 13
  4. D. 5

Correct answer: A. 7

The adjacent differences telescope to the last element minus the first, which is 8 - 1 = 7. That is smaller than the sum of absolute differences, which is 11.

More Python Programming questions

Exams that ask this topic