ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print('%.3g' % 0.0001234, '%.3g' % 123456.0, '%g' % 1e-5, '%G' % 1e-10)
  1. A. 0.000123 1.23e+05 1e-05 1E-10
  2. B. 0.000123 1.23e+05 1e-5 1E-10
  3. C. 0.000123 123000 1e-05 1E-10
  4. D. 0.00012 1.23e+05 1e-05 1E-10

Correct answer: A. 0.000123 1.23e+05 1e-05 1E-10

%.3g keeps three significant digits and switches to exponent form for large values. %g uses exponent form for small numbers below 1e-4, and %G does the same with an uppercase E.

More Python Programming questions

Exams that ask this topic