ProgrammingVery hardCAT · MBA placement

What is printed?

What is printed?
print(sum(range(10**6)) % 7)
  1. A. 1
  2. B. 3
  3. C. 6
  4. D. 0

Correct answer: D. 0

The sum equals 10^6 times (10^6 - 1) divided by 2. Because 10^6 is 1 modulo 7, the factor 10^6 - 1 is divisible by 7, so the sum is a multiple of 7.

More Python Programming questions

Exams that ask this topic