ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print(bin(29 ^ 15).count('1'))- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
XOR marks the bit positions where two numbers differ, so the number of ones in 29 ^ 15 is the number of bit flips needed. 29 is 11101 and 15 is 01111, and they differ in two positions.
More Python Programming questions
- What is printed? python from functools import lrucache @lrucache(maxsize=None) def p(n, m): if n == 0: return 1 if n < 0 or m == 0: return…
- What is printed? python import math print(sum(map(int, str(math.factorial(10)))))
- What is printed? python x = 'abc' print(x.islower() and x.isalpha(), ''.isdigit())
- What is printed? python it = iter('ab') print(next(it), list(it), next(it, 'end'))
- What is printed? python print([n for n in range(8) if n and n & (n - 1) == 0])
- What is printed? python import heapq a = [5, 1, 4] heapq.heapify(a) print([heapq.heappop(a) for in range(len(a))], a)