ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print(sum(x for x in range(1, 101) if x % 3 == 0 or x % 5 == 0))
  1. A. 2318
  2. B. 2420
  3. C. 2500
  4. D. 2418

Correct answer: D. 2418

The multiples of 3 add to 1683 and the multiples of 5 to 1050. Multiples of 15 are counted twice, so subtract 315 to get 2418.

More Python Programming questions

Exams that ask this topic