def check_happy(M,D): return M == D // 10 + D % 10 Y = 2015 cnt = 0 if Y % 4 == 0 and Y % 100 != 0: lim = {1:31,2:29,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31} elif Y % 100 == 0 and Y % 400 != 0: lim = {1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31} else: lim = {1:31,2:29,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31} for M in lim: for D in range(1,lim[M]+1): if check_happy(M,D): cnt += 1 print(cnt)