def evaluate(lists,final): """Performs arithmetic and logical operations""" if ops.null(lists):return final[0] elif ops.first(lists)=='(':return evaluate(ops.rest(lists),final) elif ops.first(lists).isdigit():return evaluate(ops.rest(lists),ops.append(final,[int(ops.first(lists))])) elif ops.first(lists)==')': op=opdet(final) if op=='+':f=add elif op=='*':f=mul elif op=='/':f=div elif op=='-':f=sub elif op=='%':f=mod elif op=='>':f=gt elif op=='and':f=and_ elif op=='<':f=lt elif op=='=':f=eq result=ops.last(final) final=ops.rest1(final) while type(ops.last(final))==int: result=int(f(ops.last(final),result)) final=ops.rest1(final) final=ops.rest1(final) return evaluate(ops.rest(lists),ops.append(final,[result])) else:return evaluate(ops.rest(lists),ops.append(final,[ops.first(lists)]))
def opdet(dummy): """Determines the operator""" if type(ops.last(dummy))==int:return opdet(ops.rest1(dummy)) else:return ops.last(dummy)