ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(len('%-8.3f|' % 3.14159), len('%08.3f' % -3.14159), '%08.3f' % -3.14159)
  1. A. 8 8 -003.142
  2. B. 9 8 -003.142
  3. C. 9 9 -0003.142
  4. D. 9 8 -3.142

Correct answer: B. 9 8 -003.142

%-8.3f gives 3.142 padded to width eight, plus the bar, for nine characters. %08.3f puts the sign first and zero-pads to eight characters total.

More Python Programming questions

Exams that ask this topic