c = [31,28,31,30,31,30,31,31,30,31,30,31] r = 0 for i in range(len(c)): for j in range(1,c[i]+1): yy = sum(int(y) for y in str(j)) if yy == (i+1): r += 1 print(r)