I'm trying to solve a problem of a course I'm doing but I can not imagine a way to solve it.
I need to create a program where the user type any expression that uses parentheses.
My application should look at whether the last expression has the parentheses open and closed in the correct order, and I have no idea how to do this analysis, could you help me?
algebra = list()
aberto = fechado = 0
expressao = str(input('Digite sua expressão algébrica com parênteses: '))
if expressao == '(':
aberto += 1
elif expressao == ')':
fechado += 1
if aberto == fechado:
algebra.append(expressao)
print(f'A sua expressão {algebra} está correta!')
print(f'Sua expressão está incorreta, verifique seus parênteses {algebra}')