数字2 python

题目:小蓝特别喜欢 2,今年是公元 2020 年,他特别高兴。

他很好奇,在公元 1 年到公元 2020 年(包含)中,有多少个年份的数位中包含数字 2?

ass = 0
for i in range(1,2021):
   if str(i).count('2')!=0:
       ass+=1
print(ass)



563

你可能感兴趣的:(python)