ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(str(0.5), str(0.25 + 0.125), 0.1 + 0.25)
  1. A. 0.5 0.375 0.35000000000000003
  2. B. 0.5 0.375 0.35
  3. C. 0.5 0.3750 0.35
  4. D. 0.5 0.375 0.3500000000000001

Correct answer: B. 0.5 0.375 0.35

0.5 and 0.375 are exact in binary, so they print as written. 0.1 + 0.25 rounds to the double whose shortest repr is 0.35.

More Python Programming questions

Exams that ask this topic