ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(sum(x * x for x in range(-3, 4)), sum(abs(x) for x in range(-3, 4)))
  1. A. 28 12
  2. B. 28 0
  3. C. 12 28
  4. D. 28 6

Correct answer: A. 28 12

The squares of -3 to 3 are 9, 4, 1, 0, 1, 4, 9, which sum to 28. The absolute values sum to 3 + 2 + 1 + 0 + 1 + 2 + 3 = 12.

More Python Programming questions

Exams that ask this topic