2

I am writing a function to make a 'digital root', which adds all digits of a number together recursively until it is one digit.

When I ask the function to return a value, it returns 'None', but if I ask it to print the value, it returns the correct answer.

Code:

def digital_root(n):
    if len(str(n)) != 1:
        list = []
        for i in str(n):
            list.append(int(i))
        n = sum(list)
        digital_root(n)
    else:
        return n
pppery
  • 3,731
  • 22
  • 33
  • 46
  • 4
    You didn't return anything inside if() condition, return digital_root(n) at the end of if condition. – Strange Jun 10 '20 at 17:05

0 Answers0