cnt = 0 dm = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] for m in range(12): for d in range(dm[m]): x = m + 1 y = d+1 yy = [int(i) for i in list(str(y))] if x == sum(yy): #print(x, y, yy) cnt += 1 print(cnt)