Find first and last digits of a number | Find the first digit ; Remove last digit from number till only one digit is left ; return the first digit ; Find the last digit ; return the last digit ; Driver Code
def firstDigit ( n ) : NEW_LINE INDENT while n >= 10 : NEW_LINE INDENT n = n / 10 ; NEW_LINE DEDENT return int ( n ) NEW_LINE DEDENT def lastDigit ( n ) : NEW_LINE INDENT return ( n % 10 ) NEW_LINE DEDENT n = 98562 ; NEW_LINE print ( firstDigit ( n ) , end = " ▁ " ) NEW_LINE print ( lastDigit ( n ) ) NEW_LINE