ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(sum(range(1, 101)) ** 2 - sum(i * i for i in range(1, 101)))
  1. A. 25164150
  2. B. 25502500
  3. C. 338350
  4. D. 25164151

Correct answer: A. 25164150

The square of the sum minus the sum of the squares is the classic Project Euler difference. 5050 squared is 25502500 and the sum of squares is 338350, so the difference is 25164150.

More Python Programming questions

Exams that ask this topic