ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print('%08.2f' % -1.5, '%+08d' % 42, '%-+5d|' % 7, '%x' % -255)
  1. A. -0001.5 +0000042 +7 | -ff
  2. B. -0001.50 +0000042 +7 | -ff
  3. C. -0001.50 +42 +7 | -ff
  4. D. -0001.50 +0000042 +8 | -ff

Correct answer: B. -0001.50 +0000042 +7 | -ff

%08.2f keeps the sign first and zero-pads to eight characters. %+08d zero-pads a signed integer, and %-+5d left-aligns the signed 7 in five columns. %x on a negative number prints a minus sign and the digits.

More Python Programming questions

Exams that ask this topic