ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
x, count = 0b1011011, 0
while x:
x &= x - 1
count += 1
print(count, bin(0b1011011).count('1'))- A. 4 5
- B. 5 4
- C. 5 5
- D. 6 5
Correct answer: C. 5 5
x & (x - 1) clears the lowest set bit each time, so the loop runs once per set bit. 0b1011011 has five ones, so both values are 5.
More Python Programming questions
- What is printed? python def isanagram(a, b): return sorted(a) == sorted(b) print(isanagram('listen', 'silent'), isanagram('abc', 'abcc')…
- What is printed? python print(pow(3, 1018, 7), pow(3, 6, 7), pow(3, 1018 % 6, 7))
- What is printed? python print(sum(range(10)) / len(range(10)), sum(range(10)) // len(range(10)), sum(range(1, 11)) % 7)
- What is printed? python n = 12345 print(n // 10 3 % 10, n % 10 3 // 100, str(n)[1], n // 1000 % 10 == int(str(n)[1]))
- What is printed? python import math print(math.gcd(240 - 1, 220 - 1) == 220 - 1, math.lcm(12, 18) == 36, math.gcd(1030, 1020) == 1020)
- What is printed? python s = 'racecar level noon python' print([w for w in s.split() if w == w[::-1]], len([w for w in s.split() if w ==…