#141BeginnerLoops· while Loops
Sum of Digits
Input format
`n`: an integer.
Output format
A list `[digit_sum, digital_root]`.
Examples
Input: n = 9875
Output: [29,2]
9 + 8 + 7 + 5 = 29, then 2 + 9 = 11, then 1 + 1 = 2.
Input: n = -405
Output: [9,9]
The sign is ignored: 4 + 0 + 5 = 9, already one digit.
Constraints
- -10^18 <= n <= 10^18
Study first
- #python
- #loops
- #while
- #modulo