+ 1
Balancing Parentheses
class Stack: def __init__(self): self.items = [] def is_empty(self): return self.items == [] def push(self,item): self.items.insert(0,item) def pop(self): return self.items.pop(0) def print_stack(self): print(self.items) def balanced(stack): #your code goes here x=Stack() for i in x: if i=='(': x.push(i) elif i==')': if x.is_empty(): return False else: x.pop() return x.is_empty() print(balanced(input()))
6 Réponses
+ 3
What is your question?
Please put your code in a script and link the script then.
+ 1
Okay, go to Code section, click on the little green +, select python.
Copy your code in this script and save it. Then come here and click on the little + one the right select your code bit.
+ 1
Looks like you need "return" before "False" in the elif block
+ 1
Thanks guys ive managed to solve this now.
0
Sorry never done this before lol,
0
Thank you