import datetime dt = datetime.date(2015, 1, 1) count = 0 while dt.year == 2015: m =dt.month d_10 = dt.day // 10 d_1 = dt.day % 10 if m == d_10 + d_1: count += 1 dt += datetime.timedelta(days=1) print(count)