Data Structures & AlgorithmsModerateTCS NQT · basics

Problem: What is the sum of the squares of the odd numbers from 1 to 10? Run the code.

Problem: What is the sum of the squares of the odd numbers from 1 to 10? Run the code.
print(sum(x * x for x in range(1, 11) if x % 2 == 1))
What is printed?
  1. A. 130
  2. B. 175
  3. C. 165
  4. D. 385

Correct answer: C. 165

1 + 9 + 25 + 49 + 81 = 165. Summing all squares 1 to 10 gives 385, which is the trap.

More Coding Interview Problems questions

Exams that ask this topic