解去年蓝桥杯的编程题目

img


我个人是这么做的,请问这么做哪儿错了

img

然后求大佬弄个好点的代码



n=1
#字典用来统计每个数字用了多少次
totals= {str(i):0 for i in range(10)}

while n:
    for i in range(10):
        if str(i) in str(n):
            totals[str(i)] += str(n).count(str(i))
            if totals[str(i)] > 2021:
                print(n)
                print(totals)
                n=-1
                
    n += 1