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))

24th Apr 2023, 2:43 PM
ARBEIT MANN
ARBEIT MANN - avatar
3 Answers
+ 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.
24th Apr 2023, 3:32 PM
JaScript
JaScript - avatar
0
return not (stack)
24th Apr 2023, 3:03 PM
tamaslud
tamaslud - avatar
0
Sorry for my previous comment, what is the question?
24th Apr 2023, 3:06 PM
tamaslud
tamaslud - avatar