Question 8
Back to Exercise
What is the output of the following Python program?
def ds(n):
return n if n < 10 else n % 10 + ds(n // 10)
print(ds(9875), ds(7), ds(ds(9875)))
- A 29 7 2
- B 9875 7 29
- C 28 7 10
- D 29 7 11 Correct
Correct Answer: Option D
9 + 8 + 7 + 5 = 29, and the digits of 29 sum to 11.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!