ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print('%s|%s' % ('a', 'b'), 'ok', '%5.1f%%' % 99.55)
  1. A. a|b ok 99.3%
  2. B. a|b ok 99.6%
  3. C. a|b ok 99.5%
  4. D. a|b no 99.5%

Correct answer: C. a|b ok 99.5%

Two %s fields print a and b, separated by a bar. 99.55 is stored a little below the midpoint, so %5.1f gives 99.5, padded to width five and followed by a literal percent sign.

More Python Programming questions

Exams that ask this topic