Check whether sum of digits at odd places of a number is divisible by K | Python3 implementation of the above approach ; Converting integer to string ; Traversing the string ; Driver code
def sumDivisible ( n , k ) : NEW_LINE INDENT sum = 0 NEW_LINE num = str ( n ) NEW_LINE for i in range ( len ( num ) ) : NEW_LINE INDENT if ( i % 2 != 0 ) : NEW_LINE INDENT sum = sum + int ( num [ i ] ) NEW_LINE DEDENT DEDENT if sum % k == 0 : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT n = 592452 NEW_LINE k = 3 NEW_LINE if sumDivisible ( n , k ) == True : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT