Python - ParĆ©ntesis Equilibrados - No me funcionĆ³ el Ćŗltimo caso de prueba de esa prĆ”ctica ayuda | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Python - ParĆ©ntesis Equilibrados - No me funcionĆ³ el Ćŗltimo caso de prueba de esa prĆ”ctica ayuda

if __name__ == '__main__': cadena = [x for x in input() if x in "{}[]()"] if len(cadena) % 2 != 0 or len(cadena) == 0: respuesta = "False" else: abierto=0 cerrado=0 for a in cadena: if a=="(": abierto+=1 else: cerrado+=1 if abierto==cerrado: respuesta="True" else: respuesta="False" print(respuesta) https://code.sololearn.com/cOhyQfO0KAT5/?ref=app

22nd Jan 2023, 2:51 AM
SANTIAGO DE JESUS SOSA TREJO
SANTIAGO DE JESUS SOSA TREJO - avatar
2 Respostas
- 1
code is working perfectly I'm not fluent in Spanish but the thing i understood is you need to check the parenthesis which the given string is closed or not but this only work for "( )"
22nd Jan 2023, 5:24 PM
Thilina Dajahetti
Thilina Dajahetti - avatar
0
You are right that is what my code does and I do better I have to expand the others "() {} []". Thank you very much.
22nd Jan 2023, 5:45 PM
SANTIAGO DE JESUS SOSA TREJO
SANTIAGO DE JESUS SOSA TREJO - avatar