ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
print([n for n in range(100, 1000) if sum(int(d) ** 3 for d in str(n)) == n])
  1. A. [153, 370, 371, 407]
  2. B. [153, 370, 371]
  3. C. [153, 407]
  4. D. [153, 370, 371, 401]

Correct answer: A. [153, 370, 371, 407]

These are the three-digit Armstrong numbers, where each digit cubed sums to the number itself. 407 is the fourth one, and the list is the complete set in this range.

More Python Programming questions

Exams that ask this topic