Question DSA-REC-0023
EasyWhat is the output of this code?
def s(n):
return 0 if n == 0 else n % 10 + s(n // 10)
print(s(1234))
- A.
10
- B.
1234
- C.
Show answer and explanation
Answer: A
It adds the last digit and recurses on the rest: 4 + 3 + 2 + 1 = 10.