ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: B. 2418

Sum of multiples of 3 up to 100 is 1683 and of 5 is 1050. Multiples of 15 were counted twice and their sum is 315, so the total is 1683 + 1050 - 315 = 2418.

More Python Programming questions

Exams that ask this topic