Data Structures & AlgorithmsHardTCS NQT Digital · Python semantics

Problem: What does the following print?

Problem: What does the following print?
print(round(1.23456, 2), round(-2.5))
What is printed?
  1. A. 1.23 -3
  2. B. 1.24 -2
  3. C. 1.23 -2.0
  4. D. 1.23 -2

Correct answer: D. 1.23 -2

Rounding to two decimals gives 1.23, and round uses banker's rounding so -2.5 becomes -2.

More Coding Interview Problems questions

Exams that ask this topic