Answer to Question #229160 in Python for kaavya

Question #229160

Number of digits until N

Given an integer N, write a program that prints the count of the total number of digits between 1 and N.

Input

The input is a positive integer.

Output

The output should be a single line containing the count of the digits up to the given number.

Explanation

Given

N = 10From 1 to 9, each number contains a single digit. From 10 onwards, the numbers contain two digits.

So the output should be 9 + 2 =

11.

Sample Input 1

10

Sample Output 1

11

Sample Input 2

4

Sample Output 2

4




1
Expert's answer
2021-08-26T18:31:34-0400
def change(amount):
    nominals = [500, 50, 10, 1]
    d  = {}
    for nominal in nominals:
        n = 0
        while amount >= nominal:
            amount -= nominal
            n += 1
        d[nominal] = n
    return d        


def print_change(d):
    for nominal in sorted(d, reverse=True)                    :
        print(f'{nominal}: {d[nominal]}', end='  ' )
    print()
    
def main():
    n = int(input())        
    d = change(n)
    print_change(d)
    
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