Found very intersting approach to count the digits of an integers #python: from math import floor, log10 def count_digits(n): return 1 + floor(log10(n)) In [2]: count_digits(5) Out[2]: 1 In [3]: count_digits(999) Out[3]: 3 In [4]: count_digits(1000) Out[4]: 4 106 views11:52