Given a number N, count the total number of digits from 1 to n
def digits_number(x):
n = 0
while x > 0:
x //= 10
n += 1
return n
def main():
n = int(input('Enter a number: '))
s = 0
for i in range(1, n+1):
s += digits_number(i)
print(f'The total number of digits is {s}')
if __name__ == '__main__':
main()
Comments
Leave a comment