import datetime dt = datetime.datetime(year=2015, month=1, day=1) cnt = 0 for i in range(365): d = dt + datetime.timedelta(days=i) month_ = d.month day_ = d.day day_sum = (day_//10) + (day_%10) # print(month_, day_, day_sum) if month_ == day_sum: cnt += 1 print(cnt)