Lanqiao Cup preparation record - house number making

topic description

This question is a fill-in-the-blank question. After calculating the result, use the output statement in the code to output the filled result.

Xiaolan wants to make house numbers for the residents of a street.

There are a total of 20202020 residents on this street, and the house numbers are numbered from 11 to 20202020.

The way Xiaolan makes the house number is to first make the numbers from 00 to 99, and finally paste the characters on the house number as needed. For example, the house number 1017 needs to paste the characters 1, 0, 1, 71, 0, 1, 7 in sequence, that is Needs 11 characters 00, 22 characters 11, 11 characters 77.

How many characters 22 are needed to make all the house numbers from 11 to 20202020?

import os
import sys

# 请在此输入您的代码
b=0
for i in range (1,2021):
  a=str(i).count('2')
  b+=a
print(b)

Thinking and summary:

It feels stupid to always use the basic thinking of C language to solve Python problems. I always like to think a lot of logic first, forgetting that python has many super useful functions

Guess you like

Origin blog.csdn.net/qq_52045638/article/details/129595916