ProgrammingVery hardTCS NQT · Accenture

What is printed?

What is printed?
print(sum(range(5)) / len(range(5)), sum([1, 2, 3, 4]) // 4, 9 // 2 * 2 + 9 % 2)
  1. A. 2 2 9
  2. B. 2.0 2 9
  3. C. 2.0 3 9
  4. D. 2.5 2 9

Correct answer: B. 2.0 2 9

The average of 0 to 4 is 10 / 5 = 2.0 as a float. Integer floor division of 10 by 4 is 2 for the list sum, and 9 // 2 * 2 + 9 % 2 gives 8 + 1 = 9.

More Python Programming questions

Exams that ask this topic