ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(0.1 * 3 == 0.3, 0.1 * 3 == 3 * 0.1, round(0.1 * 3, 1) == 0.3, 1 - 0.9 == 0.1)
  1. A. False False True False
  2. B. False True False True
  3. C. False True True False
  4. D. True True True False

Correct answer: C. False True True False

0.1 * 3 and 3 * 0.1 give the same rounded double, which is not 0.3. round() to one decimal recovers 0.3. The subtraction 1 - 0.9 is about 0.09999999999999998, so it is not equal to 0.1.

More Python Programming questions

Exams that ask this topic