0
help please Parenthesis equilibrated 2 days un this lesson
10 Antworten
+ 1
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 stack(self):
return self.items
def balanced (expression):
s = Stack()
for i in expression:
if i == "(":
s.push(i)
if i == ")":
if "(" in s.stack():
s.pop()
else:
return False
if not s.stack():
return True
else:
return False
print(balanced (input ()))
+ 1
If there was more to edit, such as erasing lines, I would have said so :)
0
This is what you logically want to do
if i == ")":
if not "(" == s.pop():
return False
You just need to add a stack underflow protection.
0
I dont see that working can u edit
0
if i == ")":
if "(" in s.stack():
s.pop()
else:
return False
0
Thanks for trying yo help but you understand that the Code os long and It doesnt if ill erase the resto off lines ir what thats why there is a edit buttom to check
0
Now you lost me XD Too much auto-correction. I'm not sure what you want to say ...
0
Kakssjsj recently i erase all my phone data
0
Just edit the code to see that working I don't know if I have to erase the rest of lines
0
That code and giving minor error was so frustrating