ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(0.1 + 0.1 + 0.1 == 0.3, 0.1 * 3, 0.3 / 0.1, int(0.3 / 0.1))
  1. A. False 0.3 3.0 3
  2. B. False 0.30000000000000004 3.0 3
  3. C. False 0.30000000000000004 2.9999999999999996 2
  4. D. True 0.30000000000000004 2.9999999999999996 2

Correct answer: C. False 0.30000000000000004 2.9999999999999996 2

Adding 0.1 three times gives 0.30000000000000004, so the first check is False. Dividing 0.3 by 0.1 gives 2.9999999999999996 because 0.3 is slightly below its ideal value, so int truncates to 2.

More Python Programming questions

Exams that ask this topic