import datetime d = datetime.date(2015,1,1) count = 0 for i in range(365): x = d.month y = str(d.day).zfill(2) if x == int(y[0]) + int(y[1]) : count = count + 1 d = d + datetime.timedelta(1) print(count)