ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(bin(10).count('1'), (10).bit_count(), (-10).bit_count())- A. 2 2 -10
- B. 2 2 3
- C. 2 2 0
- D. 2 2 2
Correct answer: D. 2 2 2
int.bit_count counts the 1-bits of the absolute value, so -10 has the same count as 10, which is 1010 in binary and gives 2.
More Python Programming questions
- What is printed? python from collections import Counter print(Counter('abracadabra').mostcommon(3))
- What is printed? python print(float(10 16 + 1) == 10 16, 10 16 + 1 == float(10 16 + 1))
- What is printed? python x = 0 def f(): global x x += 1 return x print(f() + f() 10, x)
- What is printed? python print(0.1 + 0.2 == 0.3, round(0.1 + 0.2, 10) == 0.3, 3 0.1 == 0.3 - 0.2 + 0.1)
- What is printed? python nums = [3, 1, 2] nums2 = sorted(nums, reverse=True) nums.sort() print(nums, nums2, nums is sorted(nums))
- What is printed? python nums = [13, 22, 5, 31, 8, 3] print(sorted(nums, key=lambda x: x % 10), sorted(nums, key=lambda x: x % 10…