Digital root

Write codeEasy10 min

Your task

Given a non-negative integer n, repeatedly replace it with the sum of its digits until a single digit (0-9) remains, then return that digit. For example 38 to 3+8=11 to 1+1=2. n fits in a normal integer.

Examples

digit_root(n: int) -> int
Example 1
Inputdigit_root(38)
Output2