Arithmetic Expressions

  • + 0 comments

    Hi, Can someone tell what is the issue with this code.I get RunTimeError for 7th test case . Its not TLE Error

    def getexpression(arr,operators,curInd,curresult,expr):

    if curInd == len(arr):
             if curresult%101 ==0:
                 return([True,expr])
             else:
                 return([False,""])
    

    resultTillnow=curresult

    expTillnow=expr
    
      for op in operators:
        val2=arr[curInd]
        if op=="ADD":
            result=resultTillnow+val2
            oper="+"
        elif op=="MUL":
            result=resultTillnow*val2
            oper="*"
        else:
            result=resultTillnow-val2
            oper="-"
        nexpr=expTillnow+oper+str(val2)    
        stat,e=getexpression(arr,operators,curInd+1,result,nexpr)
        if stat:
            return([stat,e])
    return([False,""])                            
    

    def arithmeticExpressions(arr):

    operators=['ADD','MUL','SUB']
    
    stat,expr = getexpression(arr,operators,1,arr[0],str(arr[0]))  
    
        if stat:
    
        return expr
        tat:
        return(expr)
       return exprelse:
        return("")