human
Validation of Equation Given as String | Function that returns true if the equation is valid.
If it is an integer then add it to another string array.
Evaluation of 1 st operator.
Evaluation of 2 nd operator.
Evaluation of 3 rd operator.
If the LHS result is equal to the RHS.
Driver code"
Solution in Python:
assistant
#Here is code to validation of Equation Given as String and the other steps required.
 def isValid ( string ) :
	k = 0 ;
	operands = [ " " ] * 5 ;
	operators = [ " " ] * 4 ;
	ans = 0 ; ans1 = 0 ; ans2 = 0 ;
	for i in range ( len ( string ) ) :
		if ( string [ i ] != ' + ' and string [ i ] != ' = ' and string [ i ] != ' - ' ) :
			operands [ k ] += string [ i ] ;
		else :
			operators [ k ] = string [ i ] ;
			if ( k == 1 ) :
				if ( operators [ k - 1 ] == ' + ' ) :
					ans += int ( operands [ k - 1 ] ) + int ( operands [ k ] ) ;
				if ( operators [ k - 1 ] == ' - ' ) :
					ans += int ( operands [ k - 1 ] ) - int ( operands [ k ] ) ;
			if ( k == 2 ) :
				if ( operators [ k - 1 ] == ' + ' ) :
					ans1 += ans + int ( operands [ k ] ) ;
				if ( operators [ k - 1 ] == ' - ' ) :
					ans1 -= ans - int ( operands [ k ] ) ;
			if ( k == 3 ) :
				if ( operators [ k - 1 ] == ' + ' ) :
					ans2 += ans1 + int ( operands [ k ] ) ;
				if ( operators [ k - 1 ] == ' - ' ) :
					ans2 -= ans1 - int ( operands [ k ] ) ;
			k += 1
	if ( ans2 == int ( operands [ 4 ] ) ) :
		return True ;
	else :
		return False ;
if __name__ == " _ _ main _ _ " :
	string = "2 ▁ + ▁ 5 ▁ + ▁ 3 ▁ + ▁ 1 ▁ = ▁ 11" ;
	if ( isValid ( string ) ) :
		print ( " Valid " ) ;
	else :
		print ( " Invalid " ) ;