Problem p03545 (python)

Fixed submission:
def main():
    num = input()
    a, b, c, d = [int(i) for i in num]
    num_list = [a, b, c, d]
    if (a-b-c-d == 7): print('{}-{}-{}-{}=7'.format(*num_list))
    elif (a-b-c+d == 7): print('{}-{}-{}+{}=7'.format(*num_list))
    elif (a-b+c-d == 7): print('{}-{}+{}-{}=7'.format(*num_list))
    elif (a+b-c-d == 7): print('{}+{}-{}-{}=7'.format(*num_list))
    elif (a-b+c+d == 7): print('{}-{}+{}+{}=7'.format(*num_list))
    elif (a+b+c-d == 7): print('{}+{}+{}-{}=7'.format(*num_list))
    elif (a+b-c+d == 7): print('{}+{}-{}+{}=7'.format(*num_list))
    elif (a+b+c+d == 7): print('{}+{}+{}+{}=7'.format(*num_list))
                    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a, b, c, d = map(int, input().split())
    num_list = [a, b, c, d]
    if (a-b-c-d == 7): print('{}-{}-{}-{}=7'.format(*num_list))
    elif (a-b-c+d == 7): print('{}-{}-{}+{}=7'.format(*num_list))
    elif (a-b+c-d == 7): print('{}-{}+{}-{}=7'.format(*num_list))
    elif (a+b-c-d == 7): print('{}+{}-{}-{}=7'.format(*num_list))
    elif (a-b+c+d == 7): print('{}-{}+{}+{}=7'.format(*num_list))
    elif (a+b-c+d == 7): print('{}+{}-{}+{}=7'.format(*num_list))
    elif (a+b+c+d == 7): print('{}+{}+{}+{}=7'.format(*num_list))
                    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a, b, c, d = map(int, input().split())
    num_list = [a, b, c, d]
    if (a-b-c-d == 7): print('{}-{}-{}-{}=7'.format(*num_list))
    elif (a-b-c+d == 7): print('{}-{}-{}+{}=7'.format(*num_list))
    elif (a-b+c-d == 7): print('{}-{}+{}-{}=7'.format(*num_list))
    elif (a+b-c-d == 7): print('{}+{}{}-{}=7'.format(*num_list))
    elif (a-b+c+d == 7): print('{}-{}+{}+{}=7'.format(*num_list))
    elif (a+b-c+d == 7): print('{}+{}-{}+{}=7'.format(*num_list))
    elif (a+b+c+d == 7): print('{}+{}+{}+{}=7'.format(*num_list))
                    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def solve(a, b, c, d):
    op_list = ['+', '-']
    sumv = a
    for op1 in op_list:
        if op1 == '+':
            sumv += b
        else:
            sumv -= b
        for op2 in op_list:
            if op2 == '+':
                sumv += c
            else:
                sumv -= c
            for op3 in op_list:
                if op3 == '+':
                    sumv += d
                else:
                    sumv -= d
                if sumv == 7:
                    return op1, op2, op3
        sumv = a



def main():
    tmp = input()
    a, b, c, d = int(tmp[0]), int(tmp[1]), int(tmp[2]), int(tmp[3])
    op_list = ['+', '-']

    op1, op2, op3 = solve(a, b, c, d)
    print(str(a) + op1 + str(b) + op2 + str(c) + op3 + str(d) + '=7')
                    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def solve(a, b, c, d):
    op_list = ['+', '-']
    sumv = a
    for op1 in op_list:
        if op1 == '+':
            sumv += b
        else:
            sumv -= b
        for op2 in op_list:
            if op2 == '+':
                sumv += c
            else:
                sumv -= c
            for op3 in op_list:
                if op3 == '+':
                    sumv += d
                else:
                    sumv -= d
                if sumv == 7:
                    return op1, op2, op3
                sumv = a


def main():
    tmp = input()
    a, b, c, d = int(tmp[0]), int(tmp[1]), int(tmp[2]), int(tmp[3])
    op_list = ['+', '-']

    op1, op2, op3 = solve(a, b, c, d)
    print(str(a) + op1 + str(b) + op2 + str(c) + op3 + str(d) + '=7')
                    

if __name__ == '__main__':
    main()