ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
print(float('%.2f' % 0.125), '%.3e' % 12345.678)
  1. A. 0.13 1.235e+04
  2. B. 0.12 1.234e+04
  3. C. 0.125 1.235e+04
  4. D. 0.12 1.235e+04

Correct answer: D. 0.12 1.235e+04

0.125 is exact in binary, so the tie goes to the even last digit, which gives 0.12. 12345.678 rounded to three decimal places in scientific form is 1.235e+04.

More Python Programming questions

Exams that ask this topic