ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(len({x % 3 for x in range(10)}), sorted({x * x % 5 for x in range(5)}))
  1. A. 3 [0, 1, 2]
  2. B. 3 [0, 1, 4]
  3. C. 2 [0, 1, 4]
  4. D. 3 [0, 4]

Correct answer: B. 3 [0, 1, 4]

x % 3 takes only the values 0, 1 and 2. The squares of 0 to 4 are 0, 1, 4, 4, 1, and reducing mod 5 keeps 0, 1 and 4.

More Python Programming questions

Exams that ask this topic