import datetime ans = 0 dt = datetime.datetime(2015, 1, 1) while dt.year < 2016: day = dt.day a, b = divmod(day, 10) if dt.month == a + b: ans += 1 dt += datetime.timedelta(days=1) print(ans)