import calendar cal = calendar.Calendar() counter = 0 for month in range(1, 13): for day in cal.itermonthdays(2015, month): day_10, day_1 = map(int, list(str(day).zfill(2))) if month == day_10 + day_1: counter += 1 print(counter)