from datetime import date, timedelta d = timedelta(days=1) i = date(2015, 1, 1) cnt = 0 while i.year == 2015: if i.month == sum(divmod(i.day, 10)): cnt += 1 # print(i) i = i + d print(cnt)