DEV Community

Discussion on: Daily Challenge #264 - Digital Root

Collapse
 
peter279k profile image
peter279k

Here is the Python code snippets with nest while loop:

def digital_root(n):
    result = 0
    n = str(n)

    index = 0
    while len(n) != 1:
        while index < len(n):
            result += int(n[index])
            index += 1

        index = 0
        n = str(result)
        result = 0

    return int(n)