ProgrammingVery hardProduct-company MCQ pattern

What is printed?

What is printed?
print('%.3g' % 0.0001234, '%.3g' % 123456.0, '%g' % 0.5)
  1. A. 0.000123 1.23e+05 0.5
  2. B. 0.000123 123000 0.5
  3. C. 0.0001234 1.23e+05 0.5
  4. D. 0.000123 1.23e+05 0.50

Correct answer: A. 0.000123 1.23e+05 0.5

%g uses scientific notation when the exponent is below -4 or at least the precision, so 123456.0 becomes 1.23e+05. 0.0001234 has exponent -4, which still prints in fixed form with three significant digits.

More Python Programming questions

Exams that ask this topic