ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(len(set(str(i * i) for i in range(10))), sorted([(-1) ** i * i for i in range(6)]))
  1. A. 9 [-5, -3, -1, 0, 2, 4]
  2. B. 10 [-4, -2, 0, 1, 3, 5]
  3. C. 10 [-5, -3, -1, 0, 2, 4, 0]
  4. D. 10 [-5, -3, -1, 0, 2, 4]

Correct answer: D. 10 [-5, -3, -1, 0, 2, 4]

The squares of 0 to 9 give ten distinct strings. The terms (-1)**i * i are 0, -1, 2, -3, 4, -5, which sorts to [-5, -3, -1, 0, 2, 4].

More Python Programming questions

Exams that ask this topic