ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(repr(0.1), repr(1 / 3), repr(2 / 3), repr(1e-7), repr(100.0))
  1. A. 0.1 0.333333333333333 0.666666666666667 1e-07 100.0
  2. B. 0.1 0.3333333333333333 0.6666666666666666 1e-07 100.0
  3. C. 0.1 0.3333333333333333 0.6666666666666666 0.0000001 100.0
  4. D. 0.1 0.3333333333333333 0.6666666666666666 1e-7 100

Correct answer: B. 0.1 0.3333333333333333 0.6666666666666666 1e-07 100.0

repr gives the shortest string that reads back as the same double, so 1/3 needs 16 digits. Small floats use exponent form with at least two exponent digits, so 1e-7 prints as 1e-07.

More Python Programming questions

Exams that ask this topic