from datetime import datetime, timedelta curr = datetime(2015, 1, 1) end = datetime(2016, 1, 1) delta = timedelta(days=1) cnt = 0 while curr < end: if curr.month == (curr.day//10 + curr.day%10): cnt+=1 curr += delta print(cnt)