TOPIC

Runtime Error

Alejandro Tapia Barboza asked 5 months ago

Im getting this: Traceback (most recent call last): File "Main.py", line 46, in evaluar(pila, 0) File "Main.py", line 11, in evaluar evaluar(pila, i) File "Main.py", line 15, in evaluar evaluar(pila, i) File "Main.py", line 11, in evaluar evaluar(pila, i) File "Main.py", line 15, in evaluar evaluar(pila, i)

<<< THIS TRACE FILE WAS TRUNCTED >>>

this is my code:

def evaluar(pila, i):

if(pila != []):
    if(len(pila) > 2):
        e1 = pila[i]
        e2 = pila[i+1]

        if(e1 == "(" and e2 == ")"):
            pila.pop(i)
            pila.pop(i)
            evaluar(pila, i)

        else:
            i += 1
            evaluar(pila, i)

    elif(len(pila) == 2):

        if(pila[0] == ")" or pila[len(pila)-1] == "("):

            print("incorrect")
        else:
            print('correct')

else:
    print('correct')

while True:

expression = input()
if(expression!='' or len(expression) > 1000):
    pila = []
    for i in range(len(expression)):
        if(expression[i] == '(' or expression[i] == ')'):
            pila.append(expression[i])

    if(len(pila) % 2 != 0):
        print("incorrect")
    elif(pila==[]):
        print ("correct")
    elif(pila[0] == ")" or pila[len(pila)-1] == "("):
        print("incorrect")
    else:
        evaluar(pila, 0)
else:
    break

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.