ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(0.1 + 0.7, 0.1 * 7, round(0.1 * 7 * 10), 3 * 0.1 == 0.30000000000000004)
  1. A. 0.8 0.7 7 True
  2. B. 0.7999999999999999 0.7000000000000001 7 True
  3. C. 0.7999999999999999 0.7 7 False
  4. D. 0.7999999999999999 0.7000000000000001 8 False

Correct answer: B. 0.7999999999999999 0.7000000000000001 7 True

Each float operation rounds to the nearest double, so 0.1 + 0.7 and 0.1 * 7 land on different neighbours of the decimal values. The last test is True because 3 * 0.1 is exactly the double written as 0.30000000000000004.

More Python Programming questions

Exams that ask this topic