ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
print('%.2f' % 2.675, '%.2f' % 2.665, round(2.665, 2), format(2.5, '.0f'), format(0.125, '.2f'))
  1. A. 2.68 2.67 2.67 2 0.12
  2. B. 2.67 2.66 2.67 2 0.12
  3. C. 2.67 2.67 2.67 3 0.13
  4. D. 2.67 2.67 2.67 2 0.12

Correct answer: D. 2.67 2.67 2.67 2 0.12

Each decimal literal is stored as the nearest binary double, and the rounding is done on that stored value. 2.675 is stored a little below the midpoint, so it rounds down, and 0.125 is exact, so it is a tie and goes to the even digit.

More Python Programming questions

Exams that ask this topic