from datetime import datetime, timedelta delta = timedelta(days=1) now = datetime(2015, 1, 1) counter = 0 while now.year < 2016: first = now.day % 10 second = (now.day - first) / 10 if first + second == now.month: counter += 1 now += delta print(counter)