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)))
- A. 14 735
- B. 15 700
- C. 15 742
- 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
- What is printed? python print(round(-2.5), round(-3.5), round(-2.5 - 1e-9))
- What is printed? python print(7 -1 7, (7 -1) 7 == 1.0)
- What is printed? python print(int('0o777', 8) == 511, int('777', 8) - int('0o777', 0))
- What is printed? python print(len('%d' % -0), '%d' % -0.0, '%.1f' % -0.0)
- What is printed? python print(max('abc', 'abd', key=lambda s: s[::-1]), min('ba', 'ab', key=len))
- What is printed? python print(sorted([1, 10, 2], key=lambda x: str(x)[0]))