def chemical_equations_equal(eq1, eq2, exact=False):
 (left1, arrow1, right1) = split_on_arrow(eq1)
 (left2, arrow2, right2) = split_on_arrow(eq2)
 if ((arrow1 == '') or (arrow2 == '')):
  return False
 if (arrow1 != arrow2):
  return False
 try:
  factor_left = divide_chemical_expression(left1, left2)
  if (not factor_left):
   return False
  factor_right = divide_chemical_expression(right1, right2)
  if (not factor_right):
   return False
  if (factor_left != factor_right):
   return False
  if (exact and (factor_left != 1)):
   return False
  return True
 except ParseException:
  return False

def chemical_equations_equal ( eq1 , eq2 , exact = False ) : ( left1 , arrow1 , right1 ) = split_on_arrow ( eq1 ) ( left2 , arrow2 , right2 ) = split_on_arrow ( eq2 ) if ( ( arrow1 == '' ) or ( arrow2 == '' ) ) : return False if ( arrow1 != arrow2 ) : return False try : factor_left = divide_chemical_expression ( left1 , left2 ) if ( not factor_left ) : return False factor_right = divide_chemical_expression ( right1 , right2 ) if ( not factor_right ) : return False if ( factor_left != factor_right ) : return False if ( exact and ( factor_left != 1 ) ) : return False return True except ParseException : return False
check whether two chemical equations are the same .