ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print(len([x for x in range(100) if x % 7 == 0]), sum(range(0, 100, 7)))
  1. A. 14 735
  2. B. 15 700
  3. C. 15 742
  4. D. 15 735

Correct answer: D. 15 735

The multiples of 7 below 100 are 0, 7, ..., 98, which is 15 numbers. Their sum is 7 times 0 + 1 + ... + 14, which is 7 x 105 = 735.

More Python Programming questions

Exams that ask this topic