Search Results

Search found 1 results on 1 pages for 'user1716168'.

Page 1/1 | 1 

  • Python parsing error message functions

    - by user1716168
    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.

    Read the article

1