ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(str(0.1 * 3), repr(0.1 * 3) == '0.30000000000000004', 0.1 * 3 == float(repr(0.1 * 3)))
  1. A. 0.30000000000000004 True True
  2. B. 0.3 True True
  3. C. 0.30000000000000004 False True
  4. D. 0.30000000000000004 True False

Correct answer: A. 0.30000000000000004 True True

repr gives the shortest decimal string that round-trips to the same float, so converting it back gives the identical value. str and repr agree for floats in Python 3.

More Python Programming questions

Exams that ask this topic