本帖最后由 jackz007 于 2021-3-13 12:07 编辑 def count(m):
d = [0] * 10
for n in range(1 , m + 1):
while n:
i = n % 10
d[i] += 1
n //= 10
return d
d = [str(i) for i in range(10)]
e = count(int(input()))
print(dict(zip(d , e)))
运行实况:D:\00.Excise\Python>python page.py
101
{'0': 12, '1': 23, '2': 20, '3': 20, '4': 20, '5': 20, '6': 20, '7': 20, '8': 20, '9': 20}
D:\00.Excise\Python>python page.py
80999
{'0': 32189, '1': 42300, '2': 42300, '3': 42300, '4': 42300, '5': 42300, '6': 42300, '7': 42300, '8': 33300, '9': 32300}
D:\00.Excise\Python>
|