ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(bin(12345).count('1'), len(bin(12345)) - 2)
  1. A. 7 14
  2. B. 5 14
  3. C. 6 14
  4. D. 6 13

Correct answer: C. 6 14

12345 = 8192 + 4096 + 32 + 16 + 8 + 1, which has six 1-bits. Its binary form 0b11000000111001 has 14 digits, so len(bin(...)) - 2 is 14.

More Python Programming questions

Exams that ask this topic