import calendar cnt = 0 for m in range(12): for d in calendar.monthrange(2015, m + 1): if m == d // 10 + d % 10: cnt += 1 print(cnt)