list1=[2] #28 days list2=[4,6,9,11] #30days list3=[1,3,5,7,8,10,12] #31days counter = 0 #各位の和を求める関数 def digitSum(n): s = str(n) array = list(map(int,s)) #1文字ずつ数値化して配列にする return sum(array) for month in list1: for d in range(29): ds=digitSum(d) if month == ds : counter+=1 for month in list2: for d in range(31): ds=digitSum(d) if month == ds : counter+=1 for month in list3: for d in range(32): ds=digitSum(d) if month == ds : counter+=1 print(counter)