Self Numbers | Function to find the sum of digits of a number N ; Function to check for Self number ; Driver code
def getSum ( n ) : NEW_LINE INDENT sum1 = 0 ; NEW_LINE while ( n != 0 ) : NEW_LINE INDENT sum1 = sum1 + n % 10 ; NEW_LINE n = n // 10 ; NEW_LINE DEDENT return sum1 ; NEW_LINE DEDENT def isSelfNum ( n ) : NEW_LINE INDENT for m in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( m + getSum ( m ) == n ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True ; NEW_LINE DEDENT n = 20 ; NEW_LINE if ( isSelfNum ( n ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT