Check if summation of two words is equal to target word | Function to check weather summation of two words equal to target word ; Store the length of each string ; Reverse the strings A , B and C ; Stores the remainder ; Iterate in the range [ 0 , max ( L , max ( M , N ) ) ] ; Stores the integer at ith position from the right in the sum of A and B ; If i is less than L ; If i is less than M ; Update rem and curr ; If i is less than N and curr is not equal to C [ i ] - ' a ' , return " No " ; If rem is greater than 0 , return " No " ; Otherwise , return " Yes " ; Driver Code ; Given Input ; Function Call
def isSumEqual ( A , B , C ) : NEW_LINE INDENT L = len ( A ) NEW_LINE M = len ( B ) NEW_LINE N = len ( A ) NEW_LINE A = A [ : : - 1 ] NEW_LINE B = B [ : : - 1 ] NEW_LINE C = C [ : : - 1 ] NEW_LINE rem = 0 NEW_LINE for i in range ( max ( L , max ( M , N ) ) ) : NEW_LINE INDENT curr = rem NEW_LINE if ( i < L ) : NEW_LINE INDENT curr += ord ( A [ i ] ) - ord ( ' a ' ) NEW_LINE DEDENT if ( i < M ) : NEW_LINE INDENT curr += ord ( B [ i ] ) - ord ( ' a ' ) NEW_LINE DEDENT rem = curr // 10 NEW_LINE curr %= 10 NEW_LINE if ( i < N and curr != ord ( C [ i ] ) - ord ( ' a ' ) ) : NEW_LINE INDENT return " No " NEW_LINE DEDENT DEDENT if ( rem ) : NEW_LINE INDENT return " No " NEW_LINE DEDENT else : NEW_LINE INDENT return " Yes " NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = " acb " NEW_LINE B = " cba " NEW_LINE C = " cdb " NEW_LINE print ( isSumEqual ( A , B , C ) ) NEW_LINE DEDENT