from datetime import datetime, timedelta ans = 0 now = datetime(2015, 1, 1) while now <= datetime(2015, 12, 31): if now.month == now.day % 10 + now.day//10: # print(now) ans += 1 now += timedelta(days=1) print(ans)