0
def digital_root(n):
    if n > 0:
        a.append(n%10)
        if n/10 > 0:
            digital_root(n/10)
        else:
            if len(a) > 1:
                b = a
                a.clear()
                z = 0
                for i in range(len(b)):
                    z += b[i]
                digital_root(z)
            else:
                return a[0]

why it returns None?

task is: Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. The input will be a non-negative integer.

1 Answers1

0

You got None because you seem to miss return statements when you call digital_root(). Should be:

    return digital_root(n/10)

and

    return digital_root(z)
lnstadrum
  • 550
  • 3
  • 15