Python parsing error message functions

Posted by user1716168 on Stack Overflow See other posts from Stack Overflow or by user1716168
Published on 2012-11-02T07:42:15Z Indexed on 2012/11/02 11:00 UTC
Read the original article Hit count: 179

The code below was created by me with the help of many SO veterans:

The code takes an entered math expression and splits it into operators and operands for later use. I have created two functions, the parsing function that splits, and the error function. I am having problems with the error function because it won't display my error messages and I feel the function is being ignored when the code runs. An error should print if an expression such as this is entered: 3//3+4,etc. where there are two operators together, or there are more than two operators in the expression overall, but the error messages dont print. My code is below:

def errors():

    numExtrapolation,opExtrapolation=parse(expression)
    if (len(numExtrapolation) == 3) and (len(opExtrapolation) !=2):
        print("Bad1")
    if (len(numExtrapolation) ==2) and (len(opExtrapolation) !=1):
        print("Bad2")


def parse(expression):
    operators= set("*/+-")
    opExtrapolate= []
    numExtrapolate= []
    buff=[]
    for i in expression:
        if i in operators:
            numExtrapolate.append(''.join(buff))
            buff= []
            opExtrapolate.append(i)
            opExtrapolation=opExtrapolate
        else:
            buff.append(i)
    numExtrapolate.append(''.join(buff))
    numExtrapolation=numExtrapolate
    #just some debugging print statements
    print(numExtrapolation)
    print("z:", len(opExtrapolation))
    return numExtrapolation, opExtrapolation

    errors()

Any help would be appreciated. Please don't introduce new code that is any more advanced than the code already here. I am looking for a solution to my problem... not large new code segments. Thanks.

© Stack Overflow or respective owner

Related posts about parsing

Related posts about function