ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print(format('x', '>4') + '|' + format(3.14159, '^9.2f') + '|' + format(42, '+') + '|' + format(1234567, ','))
  1. A. x| 3.14 |+42|1234567
  2. B. x| 3.14 |+42|1,234,567
  3. C. x| 3.14 |+43|1,234,567
  4. D. x| 3.14 |+42|12,34,567

Correct answer: B. x| 3.14 |+42|1,234,567

Centering pads the leftover space with more on the right when the total is odd, which gives two spaces left and three right in a width of nine. The + sign prints for positive numbers, and the comma flag groups digits by thousands.

More Python Programming questions

Exams that ask this topic