Check if given number contains a digit which is the average of all other digits | Function which checks if a digits exists in n which is the average of all other digits ; Calculate sum of digits in n ; Store digits ; Increase the count of digits in n ; If average of all digits is integer ; Otherwise ; Driver code
def check ( n ) : NEW_LINE INDENT digits = set ( ) NEW_LINE temp = n NEW_LINE Sum = 0 NEW_LINE count = 0 NEW_LINE while ( temp > 0 ) : NEW_LINE INDENT Sum += temp % 10 NEW_LINE digits . add ( temp % 10 ) NEW_LINE count += 1 NEW_LINE temp = temp // 10 NEW_LINE DEDENT if ( ( Sum % count == 0 ) and ( ( int ) ( Sum / count ) in digits ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT n = 42644 NEW_LINE check ( n ) NEW_LINE