import datetime date = datetime.datetime(2015, 1, 1, 0, 0) until = datetime.datetime(2016, 1, 1, 0, 0) ans = 0 while date < until: str_date = date.strftime("%m %d") m, d = str_date.split() m, d = int(m[0]) + int(m[1]), int(d[0]) + int(d[1]) if m == d: ans += 1 date += datetime.timedelta(day=1) print(ans)