Shrink to One Digit

Sometimes a large number is reduced to a single check digit, which is useful in puzzles and simple validation rules. Write digital_root, which adds the digits of n, then adds the digits of the result, and keeps going until only one digit remains. Return that final digit.

Примеры

Ввод
38
Вывод
2
Ввод
0
Вывод
0
Ввод
9
Вывод
9

Нужно реализовать

def digital_root(n: int) -> int:

Теги

math
PostgreSQLv16

Koodin suorituksen tulos näkyy tässä

Visible tests
1
Input
38
Expected2
2
Input
0
Expected0
3
Input
9
Expected9
4
Input
12345
Expected6
5
Input
99999
Expected9
6
Input
100
Expected1
Focus radio
Paused · SomaFM · Fluid