0
How do I solve this
def balanced(expression): stack = [] for char in expression: if char == "(": stack.append(char) elif char == ")": if not stack: return False stack.pop() return not stack expression = "(a( ) eee) )" print(balanced(expression))
3 Respuestas
+ 8
Look on your last statement of the function, this should be a boolean.
Very important is to think about that your code has to input the expression. In this way will the code authomatically tested for different input data (expressions).
By the way please tag a programming language.
0
return not (stack)
0
Sorry for my previous comment, what is the question?