ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(sum(x for x in range(1, 11) if x & 1), sum(x for x in range(1, 11) if x & 2))
- A. 30 28
- B. 25 18
- C. 25 28
- D. 25 25
Correct answer: C. 25 28
The odd numbers from 1 to 10 sum to 25. Numbers with the value-2 bit set are 2, 3, 6, 7 and 10, which sum to 28.
More Python Programming questions
- What is printed? python x = 'AbC' print(x.swapcase(), x.lower() < x.upper(), sorted(x) == ['A', 'C', 'b'])
- What is printed? python print(max(range(5), key=lambda x: -abs(x - 2)), min(range(5), key=lambda x: abs(x - 2)))
- What is printed? python print(sum(divmod(17, 5)), divmod(-17, 5)[1], 17 % 5 - (-17) % 5)
- What is printed? python def prodexcept(a): n = len(a) out = [1] n left = 1 for i in range(n): out[i] = left left = a[i] right = 1 for i in…
- What is printed? python import bisect def span(a, x): lo = bisect.bisectleft(a, x) if lo == len(a) or a[lo] != x: return (-1, -1) return…
- What is printed? python def palsub(s): n = len(s) best = '' for c in range(2 n - 1): l, r = c // 2, c // 2 + c % 2 while l >= 0 and r < n…