ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(1 / 2 + 1 // 2 + 1 % 2, 1 / 2 * 2 == 1, 3 * 1 / 2 == 3 * (1 / 2))
  1. A. 1.0 True True
  2. B. 1.5 False True
  3. C. 1.5 True False
  4. D. 1.5 True True

Correct answer: D. 1.5 True True

Multiplication and division run left to right, so 3 * 1 / 2 equals 3 * (1 / 2) because both evaluate 1.5 in float. The first value adds 0.5, 0 and 1 to get 1.5.

More Python Programming questions

Exams that ask this topic