I'm trying to solve a problem on CodeWars with the following specifications:
"Write a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit."
My solution is as follows:
def persistence(n,count = 0):
n = list(str(n))
if len(n) <= 1 :
count = 0
return count
else :
num_per = 1
for i in n :
num_per = num_per * int(i)
num_dump = num_per
if len(str(num_dump)) > 1:
count += 1
n = num_per
persistence(n,count)
else:
count = count + 1
return count
When I choose any number with more than a single digit, I get a return value of 'None'. I've narrowed down the problem to the last return statement in the second else clause. The number of counts are calculated correctly,but the return statement still returns a value of 'None'. Any help would be greatly appreciated.