ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(f'{0.1:.20f}', f'{1e16:g}', f'{123456789.0:e}', f'{2.5:.0f}', f'{3.5:.0f}')
  1. A. 0.10000000000000000555 1e+16 1.234568e+08 3 3
  2. B. 0.1 1e16 1.234568e+08 2 4
  3. C. 0.10000000000000000555 10000000000000000 1.23e+08 2 4
  4. D. 0.10000000000000000555 1e+16 1.234568e+08 2 4

Correct answer: D. 0.10000000000000000555 1e+16 1.234568e+08 2 4

0.1 is stored as a binary fraction slightly above one tenth, which shows at 20 decimals. The g format switches to exponent form at 1e16, and .0f uses round-half-to-even, so 2.5 gives 2 and 3.5 gives 4.

More Python Programming questions

Exams that ask this topic