ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print('%.2f' % 1.255, '%.2f' % 1.245, '%.1f' % 0.05, '%.1f' % 0.15)
  1. A. 1.26 1.25 0.1 0.2
  2. B. 1.25 1.24 0.1 0.2
  3. C. 1.25 1.25 0.1 0.1
  4. D. 1.25 1.25 0.0 0.1

Correct answer: C. 1.25 1.25 0.1 0.1

Each literal is stored as a double, and the stored value decides the result. 1.255 and 1.245 are both slightly off their midpoints in binary, and 0.05 and 0.15 round down in the same way.

More Python Programming questions

Exams that ask this topic