from datetime import date, timedelta def count_happy_day(year): delta = timedelta(days=1) ymd = date(year, 1, 1) count = 0 while ymd.year == year: m = ymd.month d = ymd.day if m == (d // 10) + (d % 10): count += 1 ymd += delta return count print(count_happy_day(2015))