Data Structures & AlgorithmsHardTCS NQT Digital · Python semantics

Problem: What does the following print?

Problem: What does the following print?
print(0.1 + 0.2 == 0.3, round(2.5), round(3.5))
  1. A. True 2 4
  2. B. False 2 4
  3. C. False 3 4
  4. D. False 2 3

Correct answer: B. False 2 4

0.1 + 0.2 is 0.30000000000000004 in binary floating point, and round uses banker's rounding (ties go to the even integer), giving 2 and 4.

More Coding Interview Problems questions

Exams that ask this topic