Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python程序将中缀转换为后缀时出错_Python_Runtime Error_Postfix Mta - Fatal编程技术网

python程序将中缀转换为后缀时出错

python程序将中缀转换为后缀时出错,python,runtime-error,postfix-mta,Python,Runtime Error,Postfix Mta,我编写了python程序,将中缀数学表达式转换为后缀。它对一些输入非常有效,例如A-((B+C)*D-E)*F或(A+B)*C。但是当我提交代码评分站点时,它说存在运行时错误。你能告诉我为什么我的代码有运行时错误以及如何修复它吗 str = input() result = '' stack = [] def getorder(c): return {'*':5, '/':5, '+':3, '-':3, '(':1}[c] def whoisfirst(x, y): if(

我编写了python程序,将中缀数学表达式转换为后缀。它对一些输入非常有效,例如A-((B+C)*D-E)*F或(A+B)*C。但是当我提交代码评分站点时,它说存在运行时错误。你能告诉我为什么我的代码有运行时错误以及如何修复它吗

str = input()
result = ''
stack = []

def getorder(c):
    return {'*':5, '/':5, '+':3, '-':3, '(':1}[c]

def whoisfirst(x, y):
    if(getorder(x) > getorder(y)):
        return 1;
    elif(getorder(x) < getorder(y)):
        return -1;
    else:
        return 0;

for i in str:
    if(i.isalpha()):
        result += i
    else:
        if (i == '('):
            stack.append(i)
            continue
        elif (i == ')'):
            while True:
                result += stack.pop(-1)

                if(stack[-1] == '('):
                    stack.pop(-1)
                    break
            continue


        if not stack:
            stack.append(i)
        else:
            while (whoisfirst(i, stack[-1]) != 1):
                result += stack.pop(-1)

                if not stack:
                    break
            stack.append(i)

while stack:
    result += stack.pop(-1)

print(result)
str=input()
结果=“”
堆栈=[]
订单(c):
返回{'*':5'/':5'+':3'-':3'(':1}[c]
谁是第一(x,y):
如果(getorder(x)>getorder(y)):
返回1;
elif(getorder(x)
是codechef吗?您运行了还是提交了?不是codechef,而是韩国网站baekjoon。我运行了一些测试用例的程序并提交了它,但网站说运行时出错。。。