ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
print(str(1e21), str(1e15), str(123456789.123), 1e21 == 10**21, float(10**21) == 1e21)
  1. A. 1e21 1000000000000000.0 123456789.123 True True
  2. B. 1e+21 1000000000000000.0 123456789.123 False True
  3. C. 1e+21 1000000000000000.0 123456789.123 True True
  4. D. 1e+21 1e+15 123456789.123 True True

Correct answer: C. 1e+21 1000000000000000.0 123456789.123 True True

str of a float switches to exponent form at 1e16, so 1e15 prints in full with a .0 suffix. 10**21 is exactly representable as a double, so both equality tests are True.

More Python Programming questions

Exams that ask this topic