Answer to Question #284625 in Python for PRR

Question #284625

Given a number N, count the total number of digits from 1 to n


1
Expert's answer
2022-01-04T01:10:21-0500
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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS