from datetime import date,timedelta d = date(2015, 1, 1) end = date(2016, 1, 1) delta = timedelta(days=1) ans = 0 while d < end: month = d.month day = d.day if month == sum(divmod(day, 10)): ans += 1 d += delta print(ans)