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))
- A. 2318
- B. 2420
- C. 2500
- 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
- What is printed? python print(int(float(253)) == 253, float(253 + 1) - 253, (253 + 1) - 253)
- What is printed? python print('a'.join('xyz'), 'xyz'.join(['a']), 'ab'.join(['', '']), ','.join(map(str, [1.0, 2])))
- What is printed? python print(round(0.5 3), round(4.5) + round(5.5), int(2.9999999999999996), int(3.0000000000000004))
- What is printed? python print('Python' 0 + 'x', 'Py' + 'thon' 0, len('' 100))
- What is printed? python print(len(str(2100)), str(2100)[-3:], (2100) % 1000)
- What is printed? python x = 5 x += 2 x print(x, x - 2 3 2 // 9 1, x // 4 4 + x % 4)