Largest even digit number not greater than N | function to check if all digits are even of a given number ; iterate for all digits ; if digit is odd ; all digits are even ; function to return the largest number with all digits even ; Iterate till we find a number with all digits even ; Driver Code
def checkDigits ( n ) : NEW_LINE INDENT while ( n > 0 ) : NEW_LINE INDENT if ( ( n % 10 ) % 2 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT n = int ( n / 10 ) ; NEW_LINE DEDENT return True ; NEW_LINE DEDENT def largestNumber ( n ) : NEW_LINE INDENT for i in range ( n , - 1 , - 1 ) : NEW_LINE INDENT if ( checkDigits ( i ) ) : NEW_LINE INDENT return i ; NEW_LINE DEDENT DEDENT DEDENT N = 23 ; NEW_LINE print ( largestNumber ( N ) ) ; NEW_LINE