ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(sum(i * (-1) ** i for i in range(1, 7)), (-1) ** 7 + 0.0, (-1.0) ** 2, (-2) ** -2)
  1. A. 3 -1.0 1.0 0.25
  2. B. 3 -1.0 1.0 0.5
  3. C. 2 -1.0 1.0 0.25
  4. D. 3 -1.0 2.0 0.25

Correct answer: A. 3 -1.0 1.0 0.25

The alternating sum is -1 + 2 - 3 + 4 - 5 + 6 = 3. Negative int exponents give floats, so (-2) ** -2 is 0.25.

More Python Programming questions

Exams that ask this topic