0
Please some help! what's wrong on my code? It works on my IDLE but Sololearn doesn't accept it to go on.
here is my code, the out-puts are correct I can understand for three days now. def balanced(expression): a =[] for n in expression: if n =="(": a.insert(0,1) for n in expression: if n ==")": if a!=[]: a.pop() else: return "False" print(a) if a== []: return "True" else: return"False" print(balanced(input()))
2 Respuestas
+ 4
Do you mean test cases failing?
if yes the check for input ))(( ? it accepts but should reject..
+ 1
def balanced(expression):
stack = []
for char in expression:
if char == '(':
stack.append(char)
elif char == ')':
if not stack or stack.pop() != '(':
return False
return not stack
print(balanced(input()))