Please some help! what's wrong on my code? It works on my IDLE but Sololearn doesn't accept it to go on. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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()))

3rd Mar 2023, 8:15 AM
paul amiell
paul amiell - avatar
2 Respostas
+ 4
Do you mean test cases failing? if yes the check for input ))(( ? it accepts but should reject..
3rd Mar 2023, 8:27 AM
Jayakrishna šŸ‡®šŸ‡³
+ 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()))
4th Mar 2023, 1:30 AM
Chuks AJ
Chuks AJ - avatar