Determine the total number of digits in the integer (`n>=0`) given as input to the function. For example, 9 is a single digit, 66 has 2 digits and 128685 has 6 digits. Be careful to avoid overflows/underflows.

All inputs will be valid.

Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code:
def digits(n):
	

Solutions:
def digits(n):
	return len(str(n))


from math import log10, ceil

def digits(n):
	return ceil(log10(n + 1))


from math import log10

def digits(n):
	return int(log10(n) + 1)


def digits(n):
	return len('%s' % n)


from typing import Union
from re import findall

def digits(number: Union[int, str]) -> int:
	return len(findall('\\d', str(number)))


def digits(n):
	if n >= 0:
		dl = len(str(n))
	return dl


def digits(n):
	s = str(n)
	s_1 = list(s)
	s_1 = len(s_1)
	return s_1


def digits(i):
	return len(str(i))


def digits(n):
	c = 0
	while n != 0:
		c += 1
		n = n // 10
	return c


def digits(n):
	if n == 0:
		return 1
	else:
		count = 0
		while n:
			count += 1
			n //= 10
		return count


def digits(n):
	return sum([1 for i in str(n)])


def digits(n):
	count = 0
	while n != 0:
		count += 1
		n = n // 10
	return count


def digits(n):
	n = str(n)
	digits = 0
	for (i, num) in enumerate(n):
		digits += 1
	return digits


def digits(n):
	a = 0
	for i in str(n):
		a += 1
	return a


import math

def digits(n):
	return math.log10(n) // 1 + 1


def digits(n):
	count = 0
	k = str(n)
	k = list(k)
	for num in k:
		count += 1
	return count


def digits(n):
	j = list(str(n))
	return len(j)


def digits(n):
	answer = 0
	while n != 0:
		n = n // 10
		answer += 1
	return answer


def digits(n):
	cont = 0
	while n > 9:
		n //= 10
		cont += 1
	return cont + 1


def digits(n):
	r = str(n)
	y = list(r)
	x = len(y)
	return x
	pass


def digits(n):
	sum = 0
	for num in str(n):
		sum += 1
	return sum


def digits(n):
	total = 1
	while n // 10 >= 1:
		n //= 10
		print(n)
		total += 1
	return total


from math import ceil, log

def digits(n):
	return ceil(log(n + 1, 10)) if 0 < n else 1


def digits(n):
	x = str(n)
	n = len(x)
	return int(n)


def digits(n):
	sn = str(n)
	cnt = 0
	for i in sn:
		cnt += 1
	return cnt


from math import log10, floor

def digits(n: int) -> int:
	return floor(log10(n) + 1) if n else 0


def digits(n):
	tot = 0
	while n > 0:
		tot += 1
		n //= 10
	return tot


import math

def digits(n):
	return math.floor(math.log(n) / math.log(10)) + 1
	pass


def digits(n):
	k = 0
	while n > 0:
		n = int(n / 10)
		k += 1
	return k


def digits(n):
	print(type(n))
	if isinstance(n, int):
		return len(str(n))
	return 0


def digits(n):
	len_1 = 0
	while n != 0:
		n //= 10
		len_1 += 1
	return len_1


def digits(n):
	print(n)
	z = [int(x) for x in str(n)]
	print(z)
	return len(z)


def digits(n):
	n = str(n)
	num = n.count('') - 1
	return num


def digits(n):
	s = str(n)
	return len([c for c in s])


def digits(n):
	n_str = str(n)
	n_list = n_str.split('.')
	count = len(n_list[0])
	return count


def digits(n):
	i = 0
	while n > 0:
		i += 1
		n = n // 10
	return i


def digits(n):
	total = 0
	n = str(n)
	for i in n:
		total += 1
	return total


def digits(num):
	count = 0
	if num < 10:
		return 1
	else:
		num >= 10
		num_digits = len(str(num))
		return num_digits
num = 11132424212
print(digits(num))


def digits(num):
	n_digits = 0
	while num > 0:
		num //= 10
		n_digits += 1
	return n_digits


def digits(n):
	nums = []
	n = str(n)
	for num in n:
		nums.append(n)
	return len(nums)
	pass


def digits(n):
	numar2 = str(n)
	counter = 0
	for i in numar2:
		print(i)
		counter = counter + 1
	return counter


def digits(n):
	return range(len(str(abs(n))))[-1] + 1


def digits(n):
	digits = []
	if n >= 0:
		[digits.append(d) for d in str(n)]
	return len(digits)
	pass


def digits(n):
	result = 0
	n2 = str(n)
	for i in n2:
		result += 1
	return result
	pass


def digits(n):
	n = str(n)
	count = 0
	for i in n:
		count += 1
	return count


def digits(n):
	if n == 0:
		return 1
	ans = 0
	while n != 0:
		n = n // 10
		ans += 1
	return ans


def digits(n):
	return len(ascii(n))


def digits(n):
	m = list(str(n))
	res = len(m)
	return res


def digits(n):
	d = [int(x) for x in str(n)]
	l = len(d)
	return l


def digits(n):
	n = str(n)
	n = list(n)
	size = len(n)
	return size
	pass


def digits(n):
	return 1 if n < 10 else 1 + digits(n // 10)
	pass


def digits(n):
	d = 0
	while n >= 1:
		n = n // 10
		d += 1
	return d


def digits(n):
	conv = str(n)
	counter = 0
	for i in conv:
		counter += 1
	return counter


def digits(n):
	k = 1
	while n // 10:
		k += 1
		n //= 10
	return k


def digits(n):
	return len(f'{n}')


def digits(n):
	num = 0
	while n > 0:
		n = int(n / 10)
		num = num + 1
	return num


def digits(n):
	x = str(n)
	y = len(x)
	return y


def digits(n):
	an_integer = n
	a_string = str(an_integer)
	length = len(a_string)
	return length


def digits(n):
	num_str = str(n)
	var_save = len(num_str)
	return var_save
	pass


import math

def digits(n):
	d = 1
	while n >= 10:
		d += 1
		n = math.floor(n / 10)
	return d


def digits(n):
	return len(' '.join(str(n)).split())


def digits(n):
	digit = n
	answer = 1
	while digit >= 10:
		digit = digit / 10
		answer += 1
	return answer


def digits(n):
	number = str(n)
	i = 0
	for letter in number:
		i += 1
	return i


def digits(n):
	sum = 0
	while n > 0:
		return len(str(n))


def digits(n):
	for i in str(n).split():
		return len(i)


def digits(n):
	list = [int(x) for x in str(n)]
	return len(list)


def digits(n):
	a = str(n)
	b = list(a)
	for element in b:
		if element == ',' or element == '.':
			b.remove(element)
		else:
			pass
	return len(b)


def digits(n):
	num = 0
	awnser = 0
	num = str(n)
	awnser = len(num)
	return awnser


def digits(n):
	string = str(n)
	i = 0
	for s in string:
		i += 1
	return i


def digits(n):
	count = 1
	while n >= 10:
		q = n / 10
		count += 1
		n = q
	return count


def digits(n):
	num_digits = 0
	while n > 0:
		n = n // 10
		num_digits += 1
	return num_digits