from datetime import date, timedelta res = 0 day = date(2015, 1, 1) for i in range(365): m = day.month d = sum(map(int ,list(str(day.day)))) if m == d: res += 1 day = day + timedelta(days=1) print(res)