Print all palindrome dates between the given years | Python 3 implementation of the approach ; Returns true if given year is valid ; Return true if year is a multiple pf 4 and not multiple of 100. OR year is multiple of 400. ; Returns true if given year is valid or not . ; If year , month and day are not in given range ; Handle February month with leap year ; Months of April , June , Sept and Nov must have number of days less than or equal to 30. ; Function to print the palindrome dates between the given years ; For every year ; Current year as a string ; To store the reverse of year ; Get the day and the month ; If the current palindrome date is valid ; Driver code
MAX_VALID_YR = 9999 NEW_LINE MIN_VALID_YR = 1800 NEW_LINE def isLeap ( year ) : NEW_LINE INDENT return ( ( ( year % 4 == 0 ) and ( year % 100 != 0 ) ) or ( year % 400 == 0 ) ) NEW_LINE DEDENT def isValidDate ( d , m , y ) : NEW_LINE INDENT if ( y > MAX_VALID_YR or y < MIN_VALID_YR ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( m < 1 or m > 12 ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( d < 1 or d > 31 ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( m == 2 ) : NEW_LINE INDENT if ( isLeap ( y ) ) : NEW_LINE INDENT return ( d <= 29 ) NEW_LINE DEDENT else : NEW_LINE INDENT return ( d <= 28 ) NEW_LINE DEDENT DEDENT if ( m == 4 or m == 6 or m == 9 or m == 11 ) : NEW_LINE INDENT return ( d <= 30 ) NEW_LINE DEDENT return True NEW_LINE DEDENT def printPalindromeDates ( y1 , y2 ) : NEW_LINE INDENT for year in range ( y1 , y2 + 1 , 1 ) : NEW_LINE INDENT str1 = str ( year ) NEW_LINE rev = str1 NEW_LINE rev = rev [ : : - 1 ] NEW_LINE day = int ( rev [ 0 : 2 ] ) NEW_LINE month = int ( rev [ 2 : 4 ] ) NEW_LINE rev += str1 NEW_LINE if ( isValidDate ( day , month , year ) ) : NEW_LINE INDENT print ( rev ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT y1 = 2001 NEW_LINE y2 = 2005 NEW_LINE printPalindromeDates ( y1 , y2 ) NEW_LINE DEDENT