ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print('%s and %s' % ('A', 'B'), '%(x)d-%(x)05.1f' % {'x': 3}, '%%%d' % 5)
  1. A. A and B 3-003.0 %6
  2. B. A and B 3-003 %5
  3. C. A and B 3-003.0 %5
  4. D. A and B 3-0003.0 %5

Correct answer: C. A and B 3-003.0 %5

%(x)05.1f pads to width 5 with zeros, giving 003.0. A doubled %% prints a literal percent sign, so the last value is '%5'.

More Python Programming questions

Exams that ask this topic