Problem p03545 (python)

Fixed submission:
n = str(input())

length = 4 #nの長さ
spaces = length -1

masterlist = []
opelist = ["+"] * spaces

for i in range(2 ** spaces):
    opelist = ["+"] * spaces

    for j in range(spaces):
        if i >> j & 1:
            opelist[j] = "-"
        else:
            opelist[j] = "+"

    masterlist.append(opelist)

for opes in masterlist:
    nls = list(n)
    for k in range(len(opes)):
        nls.insert(2*k+1,opes[k])
        #print(nls)
    nstr = ''.join(nls)
    if eval(nstr) == 7:
        print("{}=7".format(nstr))
        exit()

Buggy submission (verdict: Runtime Error):
n = str(input())

length = 4 #nの長さ
spaces = length -1

masterlist = []
opelist = ["+"] * spaces

for i in range(2 ** spaces):
    opelist = ["+"] * spaces

    for j in range(spaces):
        if i >> j & 1:
            opelist[j] = "-"
        else:
            opelist[j] = "+"

    masterlist.append(opelist)

for opes in masterlist:
    nls = list(n)
    for k in range(len(opes)):
        nls.insert(2*k+1,opes[k])
        #print(nls)
    nstr = ''.join(nls)
    if eval(nstr) == 7:
        print(f"{nstr}=7")
        exit()

Buggy submission (verdict: Runtime Error):
n = str(input())

length = 4 #nの長さ
spaces = length -1

masterlist = []
opelist = ["+"] * spaces

for i in range(2 ** spaces):
    opelist = ["+"] * spaces

    for j in range(spaces):
        if i >> j & 1:
            opelist[j] = "-"
        else:
            opelist[j] = "+"

    masterlist.append(opelist)

for opes in masterlist:
    nls = list(n)
    for k in range(len(opes)):
        nls.insert(2*k+1,opes[k])
        #print(nls)
    nstr = ''.join(nls)
    if eval(nstr) == 7:
        print(f"{nstr}=7")
        exit()

Buggy submission (verdict: Runtime Error):
n = str(input())

length = 4 #nの長さ
spaces = length -1

masterlist = []
opelist = ["+"] * spaces

for i in range(2 ** spaces):
    opelist = ["+"] * spaces

    for j in range(spaces):
        if i >> j & 1:
            opelist[j] = "-"
        else:
            opelist[j] = "+"

    masterlist.append(opelist)

for opes in masterlist:
    nls = list(n)
    for k in range(len(opes)):
        nls.insert(2*k+1,opes[k])
        #print(nls)
    nstr = ''.join(nls)
    if eval(nstr) == 7:
        print(f"{nstr}=7")
        exit()

Buggy submission (verdict: Runtime Error):
n = str(input())

length = 4 #nの長さ
spaces = length -1

masterlist = []
opelist = ["+"] * spaces

for i in range(2 ** spaces):
    opelist = ["+"] * spaces

    for j in range(spaces):
        if i >> j & 1:
            opelist[j] = "-"
        else:
            opelist[j] = "+"

    masterlist.append(opelist)

for opes in masterlist:
    nls = list(n)
    for k in range(len(opes)):
        nls.insert(2*k+1,opes[k])
        #print(nls)
    nstr = ''.join(nls)
    if eval(nstr) == 7:
        print(f"{nstr}=7")
        exit()

Buggy submission (verdict: Runtime Error):
n = str(input())

length = 4 #nの長さ
spaces = length -1

masterlist = []
opelist = ["+"] * spaces

for i in range(2 ** spaces):
    opelist = ["+"] * spaces

    for j in range(spaces):
        if j >> j & 1:
            opelist[j] = "-"
        else:
            opelist[j] = "+"

    masterlist.append(opelist)

for opes in masterlist:
    nls = list(n)
    for k in range(len(opes)):
        nls.insert(2*k+1,opes[k])
        #print(nls)
    nstr = ''.join(nls)
    if eval(nstr) == 7:
        print(f"{nstr}=7")
        exit()