Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: What is printed? print(f"{3.14159:.2f}", f"{42:05d}", f"{0.5:.0%}")

  1. A. 3.14 00042 0.5
  2. B. 3.14 00042 50%
  3. C. 3.14 42 50%
  4. D. 3.1 00042 50%

Correct answer: B. 3.14 00042 50%

Format specifiers: .2f rounds to two decimals, 05d pads with zeros to width 5, and .0% multiplies by 100 before formatting. Padding with spaces instead of zeros gives a different result.

More Coding Interview Problems questions

Exams that ask this topic