Data Structures & AlgorithmsModerateTCS NQT Digital · Python semantics

Problem: What does the following print?

Problem: What does the following print?
print(int('0b101', 0), int('101', 2), 7 // 2 * 2)
  1. A. 5 5 7
  2. B. 0 5 6
  3. C. 5 101 6
  4. D. 5 5 6

Correct answer: D. 5 5 6

int with base 0 honours the 0b prefix, and 7 // 2 * 2 = 3 * 2 = 6 because floor division binds before the multiplication's result is taken.

More Coding Interview Problems questions

Exams that ask this topic