ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(sum([1, 2, 3]) / 2 // 1, 7 // 2 / 2, divmod(7.0, 2)[0] == 7 // 2)
  1. A. 3 1.5 True
  2. B. 3.0 1.5 False
  3. C. 3.0 3.5 True
  4. D. 3.0 1.5 True

Correct answer: D. 3.0 1.5 True

6 / 2 is 3.0, and floor division by 1 keeps it a float. 7 // 2 / 2 is 3 / 2 = 1.5, and divmod of a float gives a float quotient equal to 3.0.

More Python Programming questions

Exams that ask this topic