ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(sum(bin(i).count('1') for i in range(8)))- A. 8
- B. 10
- C. 12
- D. 9
Correct answer: C. 12
The bit counts for 0 to 7 are 0, 1, 1, 2, 1, 2, 2, 3. Their sum is 12.
More Python Programming questions
- What is printed? python seen = {} for i, x in enumerate([2, 7, 11, 15]): if 9 - x in seen: print((seen[9 - x], i)) break seen[x] = i
- What is printed? python print(len(bin(10 6)) - 2, len(bin(2 20)) - 2)
- What is printed? python print(max(range(10), key=lambda x: x % 4), min([], default=7))
- What is printed? python print(3 -1, 7 // 0.5, 2 0.5 2 0.5 == 2)
- What is printed? python print(float('%.2f' % 0.125), '%.3e' % 12345.678)
- What is printed? python print(int(str(2 70)[:5]), len(str(2 70)))