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

18th Nov 2021, 7:11 PM
Aaron Robinson
6 Respuestas
+ 3
What is your question? Please put your code in a script and link the script then.
18th Nov 2021, 8:15 PM
Lisa
Lisa - avatar
+ 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.
18th Nov 2021, 8:29 PM
Lisa
Lisa - avatar
+ 1
Looks like you need "return" before "False" in the elif block
19th Nov 2021, 1:19 AM
Steve
Steve - avatar
+ 1
Thanks guys ive managed to solve this now.
19th Nov 2021, 1:29 AM
Aaron Robinson
0
Sorry never done this before lol,
18th Nov 2021, 8:21 PM
Aaron Robinson
0
Thank you
18th Nov 2021, 8:43 PM
Aaron Robinson