import datetime as dt date = dt.datetime(2015, 1, 1, 0, 0) count = 0 for i in range(365): #print(date.month,list(map(int,list(str(date.day))))) if date.month==sum(list(map(int,list(str(date.day))))): count+=1 date += dt.timedelta(days=1) print(count)