Narcissistic number | function to count digits ; Returns true if n is Narcissistic number ; Count the number of digits ; Calculates the sum of digits raised to power ; Driver code
def countDigit ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT return ( 1 + countDigit ( n // 10 ) ) NEW_LINE DEDENT def check ( n ) : NEW_LINE INDENT l = countDigit ( n ) NEW_LINE dup = n ; sm = 0 NEW_LINE while ( dup ) : NEW_LINE INDENT sm = sm + pow ( dup % 10 , l ) NEW_LINE dup = dup // 10 NEW_LINE DEDENT return ( n == sm ) NEW_LINE DEDENT n = 1634 NEW_LINE if ( check ( n ) ) : NEW_LINE INDENT print ( " yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " no " ) NEW_LINE DEDENT