from datetime import date def is_valid(number: int) -> bool: ten = int(number/10) one = number % 10 num = ten + one if num < 1 or 12 < num: return False try: date(2015, num, ten * 10 + one) return True except Exception: return False count: int = 0 for i in range(31): if is_valid(i + 1): count += 1 print(count)