Balanced Parentheses Not working
I have this code in a problem called balanced parentheses. The goal of the problem is to find balanced parentheses. For instance "(x+y)*(z-2*(6))" is balanced and "7-(3(2*9))4) (1" is not. I am passing 6 test cases but I can't pass the last one. Can you help me by solving the problem? Thanks in advance `class Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def push(self, item): self.items.append(item) def pop(self): return self.items.pop() def peek(self): return self.items[len(self.items)-1] def size(self): return len(self.items) def balanced(expression): a = Stack() for i in expression: if i == "(": a.push(i) for i in expression: if i == ")": if a.size() == 0: return False else: a.pop() if a.size() == 0: return True else: return False print(balanced(input()))`