ProgrammingHardCodeforces-style · placement coding round
What is printed?
What is printed?
x = 0b101100
print(x & (x - 1), x & -x, bin(x).count('1'))- A. 40 4 3
- B. 43 4 3
- C. 40 8 3
- D. 40 4 2
Correct answer: A. 40 4 3
x & (x-1) clears the lowest set bit, x & -x isolates it, and bin(x).count('1') counts set bits. For 44 = 101100 these give 40, 4 and 3.
More Python Programming questions
- What is printed? python M = 1000000007 print(pow(2, -1, 7), pow(3, 4, 5), (pow(10, 9, M) 2) % M)
- What is printed? python import math print(math.comb(10, 3), math.gcd(12, 18, 24), math.lcm(4, 6, 10))
- What is printed? python import itertools print(sum(b - a for a, b in itertools.pairwise([1, 4, 2, 8])))
- What is printed? python g = [[0] 3] 2 g[0][1] = 5 h = [[0] 3 for in range(2)] h[0][1] = 5 print(g, h)
- What is printed? python import heapq h = [] for w, name in [(2, 'b'), (1, 'z'), (2, 'a'), (1, 'c')]: heapq.heappush(h, (w, name)) out = []…
- What is printed? python recs = [('a', 2), ('b', 1), ('c', 2), ('d', 1)] print([n for n, v in sorted(recs, key=lambda r: r[1]…