ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
print((1 << 70).bit_count(), (2**70 - 1).bit_count(), (-1).bit_count(), (-8).bit_count())
- A. 1 70 -1 -8
- B. 1 70 1 0
- C. 1 69 1 1
- D. 1 70 1 1
Correct answer: D. 1 70 1 1
int.bit_count() counts the set bits of the absolute value, so it works on negatives too. 2**70 - 1 has seventy one-bits, and -1 and -8 each have one set bit in their absolute values.
More Python Programming questions
- What is printed? python print(f'{0.1:.20f}', f'{1e16:g}', f'{123456789.0:e}', f'{2.5:.0f}', f'{3.5:.0f}')
- What is printed? python n = float('nan') print(n in [n], [n] == [n], n == n, n is n)
- What is printed? python print(sum([0.1, 0.2, 0.3]) == 0.6, 0.1 + 0.2 + 0.3 == 0.6, 0.3 + 0.2 + 0.1 == 0.6)
- What is printed? python print(7.5 // 2, 7.5 % 2, -7.5 // 2, divmod(7.5, -2))
- What is printed? python print(max([('x', 5), ('y', 5)], key=lambda t: t[1]), min([('x', 5), ('y', 5)], key=lambda t: t[1]))
- What is printed? python print(sorted([1.0, True, 1, 0.5, False]))