ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(f'{-1.5:+.1f}', f'{0.5:.0f}', f'{1.5:.0f}', f'{-0.04:.1f}')
  1. A. -1.5 0 3 0.0
  2. B. -1.5 1 2 -0.0
  3. C. -1.5 0 1 -0.0
  4. D. -1.5 0 2 -0.0

Correct answer: D. -1.5 0 2 -0.0

The .0f format rounds exact halves to even, so 0.5 gives 0 and 1.5 gives 2. -0.04 rounds to a negative zero at one decimal, and the format keeps the minus sign.

More Python Programming questions

Exams that ask this topic