ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
def dsum(n):
    return n if n < 10 else dsum(sum(map(int, str(n))))
print(dsum(9875), dsum(0), dsum(999999999999))
  1. A. 2 0 3
  2. B. 29 0 9
  3. C. 2 1 9
  4. D. 2 0 9

Correct answer: D. 2 0 9

Repeated digit sums give the digital root. 9875 leads to 2, 0 stays 0, and twelve nines give 108 and then 9.

More Python Programming questions

Exams that ask this topic