ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
x = 3.14159
print(f'{x:.2f}|{42:>5}|{0.5:%}')
  1. A. 3.14| 42|50%
  2. B. 3.1| 42|50.000000%
  3. C. 3.14| 42|50.000000%
  4. D. 3.14| 42|5.000000%

Correct answer: C. 3.14| 42|50.000000%

The .2f spec rounds to two decimals, >5 right-aligns in five columns, and the % spec multiplies by 100 with six decimals by default.

More Python Programming questions

Exams that ask this topic