Check if all the digits of the given number are same | Python3 program for the above approach ; Function to check if all the digits in the number N is the same or not ; Get the length of N ; Form the number M of the type K * 111. . . where K is the rightmost digit of N ; Check if the numbers are equal ; Otherwise ; Driver Code
import math NEW_LINE def checkSameDigits ( N ) : NEW_LINE INDENT length = int ( math . log10 ( N ) ) + 1 ; NEW_LINE M = ( int ( math . pow ( 10 , length ) ) - 1 ) // ( 10 - 1 ) ; NEW_LINE M *= N % 10 ; NEW_LINE if ( M == N ) : NEW_LINE INDENT return " Yes " ; NEW_LINE DEDENT return " No " ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 222 ; NEW_LINE print ( checkSameDigits ( N ) ) ; NEW_LINE DEDENT