0
Hey guys can someone please tell me wat wrong with my code for the balanced paranthesis challenge
3 Antworten
+ 3
Mkhuliseni Sithole
What if )) ((
This is not balanced.
For balanced should be like this:
(())
+ 2
Mkhuliseni Sithole
Whilst I agree with A͢J , I believe your problem is not that complex allowing for the level of difficulty of the challenge.
Your responses are phrased as Strings, I believe the responses need to be boolean, so try this adaptation to your code.
open_list= ["{","(","["]
close_list= ["}",")","]"]
def balanced(expression):
#your code goes here
stack1= []
stack2= []
for i in expression:
if i in open_list:
stack1.append(i)
elif i in close_list :
stack2.append(i)
return len(stack1) == len(stack2 )
expression = input()
print(balanced (expression ))
+ 1
Okay thank you guys always helpful🙏🏿🙏🏿