Help in this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help in this code

This is the last lesson of data structures course and when run i have two cases wrong (that are not shown ) the objective is print true or False if fhe input expression is parentheses equilibrated. this is my code: def balanced(expression): #tu código va aqu par=[] for i in expression: if i== "(": par.insert(0,"(") elif i==")": if par[0]=="(": par.pop(0) else: return("False") break if par==[]: return("True") else: return("False") print(balanced(input()))

29th Aug 2022, 9:05 PM
Mabel Zavala Moreira
1 Answer
0
When list is empty and you encounter ')' from input then par[0]=='(' raise error because list is empty...
30th Aug 2022, 8:19 AM
Jayakrishna 🇮🇳