ProgrammingHardTCS NQT · Accenture

What is printed?

What is printed?
print('%5.1f|%-5d|' % (3.14159, 42))
  1. A. 3.1|41 |
  2. B. 3.1| 43|
  3. C. 3.1|42 |
  4. D. 3.14|42 |

Correct answer: C. 3.1|42 |

%5.1f gives one decimal in five columns, which pads the 3.1 with two leading spaces. %-5d left-aligns 42 in five columns.

More Python Programming questions

Exams that ask this topic