Check whether the given decoded string is divisible by 6 | Function to return the sum of the digits of n ; Function that return true if the decoded string is divisible by 6 ; To store the sum of the digits ; For each character , get the sum of the digits ; If the sum of digits is not divisible by 3 ; Get the last digit of the number formed ; If the last digit is not divisible by 2 ; Driver code
def sumDigits ( n ) : NEW_LINE INDENT sum = 0 ; NEW_LINE while ( n > 0 ) : NEW_LINE INDENT digit = n % 10 ; NEW_LINE sum += digit ; NEW_LINE n //= 10 ; NEW_LINE DEDENT return sum ; NEW_LINE DEDENT def isDivBySix ( string , n ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum += ( ord ( string [ i ] ) - ord ( ' a ' ) + 1 ) ; NEW_LINE DEDENT if ( sum % 3 != 0 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT lastDigit = ( ord ( string [ n - 1 ] ) - ord ( ' a ' ) + 1 ) % 10 ; NEW_LINE if ( lastDigit % 2 != 0 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT return True ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = " ab " ; NEW_LINE n = len ( string ) ; NEW_LINE if ( isDivBySix ( string , n ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT