ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(len([x for x in range(1, 100) if x % 3 == 0 or x % 5 == 0]), sum(x for x in range(1, 100) if x % 3 == 0 or x % 5 == 0))
- A. 46 2233
- B. 45 2318
- C. 47 2318
- D. 46 2318
Correct answer: D. 46 2318
There are 33 multiples of 3, 19 of 5 and 6 of 15 below 100, so 33 + 19 - 6 = 46. Their sum is 1683 + 950 - 315 = 2318, using inclusion-exclusion for the overlap.
More Python Programming questions
- What is printed? python print(bin(10)[::-1], int(''.join(reversed(bin(10)[2:])), 2), format(10, 'b').zfill(6))
- What is printed? python from collections import Counter c = Counter(a=1) c.subtract({'a': 3, 'b': 1}) print(c, c['a'] + c['b'])
- What is printed? python print(sorted([(2, 'b'), (1, 'z'), (3, 'a')], reverse=True))
- What is printed? python print(3 in {1, 2, 3} and 'x' in 'xyz', [] or () or None)
- What is printed? python def flat(x): for i in x: if isinstance(i, list): yield from flat(i) else: yield i print(list(flat([1, [2, [3, 4]]…
- What is printed? python print('42'.zfill(5), '-42'.zfill(5), 'ab'.center(6, ''), 'x'.ljust(3, '.') + '|')