I've been trying to find how do I do check the length of integer using recursion. For example: 100, it will say that there's 3 number. 12, it will say that there's 2 number.
What I've saw online is all about the summation of the last digit. I couldn't source for help on the length of an integer.
can someone help me out on this? I've tried to use lens to count, but my output is always 0.
def num(x):
if x == 0:
return 0
else:
return num(x / 10)
print len(str(num(100)))
I've also tried this
def num(x):
if x == 0:
return 0
else:
return num(x / 10) + len(str(x % 10))
print num(100)