ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(len('%s' % 1.0), len('%g' % 1.0), len(repr(1.0)), str(1e5), '%g' % 1e5, '%g' % 1e6)
  1. A. 3 1 1 100000.0 100000 1000000
  2. B. 3 1 3 100000 100000 1e+06
  3. C. 3 1 3 100000.0 100000 1e+06
  4. D. 3 1 3 100000.0 100000 1000000

Correct answer: C. 3 1 3 100000.0 100000 1e+06

%s and repr give 1.0, which is three characters. %g drops trailing zeros and switches to exponent form at a million, so 1e6 prints as 1e+06 while 1e5 prints as 100000. str(1e5) keeps the .0.

More Python Programming questions

Exams that ask this topic