Problem 482934 · easy · Phase 04 Non-Linear Data Structures

Checksum Digit

recursion · digits · digital root

A parcel service stamps a one-digit checksum on each label: add up the digits of the tracking number; if the result has more than one digit, add up its digits again; repeat until a single digit remains. Write checksum_digit(n) returning that final digit for a non-negative integer n, computing every digit sum recursively (no string conversion, no loops).

Examples

Input:  n = 493193
Output: 2
Explanation: 4+9+3+1+9+3 = 29, then 2+9 = 11, then 1+1 = 2.

Input:  n = 7
Output: 7

Constraints

  • 0 <= n < 10**18

Goals

  • Compose two recursive functions: one for the digit sum, one that repeats it
  • Stop when the value becomes a single digit
  • Handle 0 without an infinite loop
Starting Python…