ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
nums = [3, 1, 4, 1, 5, 9, 2, 6]
print(sorted(nums)[len(nums) // 2], sorted(nums)[(len(nums) - 1) // 2], sum(nums) / len(nums))
  1. A. 4 4 3.875
  2. B. 4 3 3.875
  3. C. 3 3 3.875
  4. D. 4 3 3.8

Correct answer: B. 4 3 3.875

Sorted, the list is 1 1 2 3 4 5 6 9, so index 4 is 4 and index 3 is 3. The sum is 31, and 31 / 8 is 3.875.

More Python Programming questions

Exams that ask this topic