qyliang/CodeNanoFix huggingface dataset:
Buggy code:
def dfs(i,Str,res):
    if i==num-1:
        if res==7:
            print(Str+"=7")
            exit()
        return
    dfs(i+1,Str+"+"+S[i+1],res+int(Str))    

n=input()
num=len(n)

Fixed code:
def dfs(i,Str,res):
    if i==num-1:
        if res==7:
            print(Str+"=7")
            exit()
        return
    dfs(i+1,Str+"+"+S[i+1],res+int(S[i+1]))
    dfs(i+1,Str+"-"+S[i+1],res-int(S[i+1]))    

S=input()
num=len(S)
dfs(0,S[0],int(S[0]))
Buggy code:
def dfs(i,s,res):
    if i==3:
        if res == 7:
            return s
    dfs(i+1,s+'+'+S[i+1],res+int(S[i+1]))
    dfs(i+1,s+'-'+S[i+1],res-int(S[i+1]))

S=input()
print(dfs(0,S[0],int(S[0]))+"=7")


Fixed code:
def dfs(i,s,res):
    if i==3:
        if res == 7:
            print(s+"=7")
            exit()
        return
 
    dfs(i+1,s+'+'+S[i+1],res+int(S[i+1]))
    dfs(i+1,s+'-'+S[i+1],res-int(S[i+1]))
 
S=input()
dfs(0,S[0],int(S[0]))
Buggy code:
def dfs(i,s,res):
    if i==3:
        if res == 7:
            print(s+"=7")
     		return
          	exit()
         
    dfs(i+1,s+'+'+S[i+1],res+int(S[i+1]))
    dfs(i+1,s+'-'+S[i+1],res-int(S[i+1]))

S=input()
dfs(0,S[0],int(S[0]))

Fixed code:
def dfs(i, Str, res):
    if i==3:
        if res==7:
            print(Str+"=7")
            exit()
        return
    
    dfs(i+1,Str+"+"+s[i+1],res+int(s[i+1]))
    dfs(i+1,Str+"-"+s[i+1],res-int(s[i+1]))

s=input()
dfs(0,s[0],int(s[0]))
Buggy code:
A = input()
a,b,c,d = A[0],A[1],A[2],A[3]
e1 = a+b+c+d
e2 = a+b+c-d
e3 = a+b-c+d
e4 = a+b-c-d
e5 = a-b+c+d
e6 = a-b+c-d
e7 = a-b-c+d
e8 = a-b+c-d
if eval(e1) == 7:
    print(e1)
elif eval(e2) == 7:
    print(e2)
elif eval(e3) == 7:
    print(e3)
elif eval(e4) == 7:
    print(e4)
elif eval(e5) == 7:
    print(e5)
elif eval(e6) == 7:
    print(e6)
elif eval(e7) == 7:
    print(e7)
elif eval(e8) == 7:
    print(e8)

Fixed code:
A = input()
a,b,c,d = A[0],A[1],A[2],A[3]
e1 = a+'+'+b+'+'+c+'+'+d
e2 = a+'+'+b+'+'+c+'-'+d
e3 = a+'+'+b+'-'+c+'+'+d
e4 = a+'+'+b+'-'+c+'-'+d
e5 = a+'-'+b+'+'+c+'+'+d
e6 = a+'-'+b+'+'+c+'-'+d
e7 = a+'-'+b+'-'+c+'+'+d
e8 = a+'-'+b+'+'+c+'-'+d
if eval(e1) == 7:
    print(e1+'=7')
elif eval(e2) == 7:
    print(e2+'=7')
elif eval(e3) == 7:
    print(e3+'=7')
elif eval(e4) == 7:
    print(e4+'=7')
elif eval(e5) == 7:
    print(e5+'=7')
elif eval(e6) == 7:
    print(e6+'=7')
elif eval(e7) == 7:
    print(e7+'=7')
elif eval(e8) == 7:
    print(e8+'=7')
Buggy code:
def DepthFirst_search(S,pre):
    global out
    #print(out)
    print('pre = {}'.format(pre))
    if len(S) == 1 :
        if pre + int(S[0]) == 7:
            out = out + '+{}'.format(int(S[0])) + '=7'
            return True
        if pre - int(S[0]) == 7:
            out = out + '-{}'.format(int(S[0])) + '=7'
            return True
        return False

    pre += int(S[0])
    if DepthFirst_search(S[1:len(S)],pre):
        #print(out)
        out = '+' + S[0] + out
        return True
    pre -= 2*int(S[0])
    if DepthFirst_search(S[1:len(S)],pre):
        #print(out)
        out = '-' + S[0] + out
        return True
    return False
out = ''
pre = 0
S = input()
DepthFirst_search(S,pre)

print(out[1:])


Fixed code:
def DepthFirst_search(S,pre):
    global out
    #print(out)
    #print('pre = {}'.format(pre))
    if len(S) == 1 :
        if pre + int(S[0]) == 7:
            out = out + '+{}'.format(int(S[0])) + '=7'
            return True
        if pre - int(S[0]) == 7:
            out = out + '-{}'.format(int(S[0])) + '=7'
            return True
        return False

    pre += int(S[0])
    if DepthFirst_search(S[1:len(S)],pre):
        #print(out)
        out = '+' + S[0] + out
        return True
    pre -= 2*int(S[0])
    if DepthFirst_search(S[1:len(S)],pre):
        #print(out)
        out = '-' + S[0] + out
        return True
    return False
out = ''
pre = 0
S = input()
DepthFirst_search(S,pre)

print(out[1:])
Buggy code:
import itertools
s = list(input())
for ops in itertools.product(['+','-'],repeat=3):
  s_i = []
  for i in range(3):
    s_i.append(s[i])
    s_i.append(ops[i])
  s_i.append(s[-1])
  s_i = "".join(s_i)
  if eval(s_i)==7:
    print(s_i+"=7")

Fixed code:
import itertools
s = list(input())
for ops in itertools.product(['+','-'],repeat=3):
  s_i = []
  for i in range(3):
    s_i.append(s[i])
    s_i.append(ops[i])
  s_i.append(s[-1])
  s_i = "".join(s_i)
  if eval(s_i)==7:
    print(s_i+"=7")
    exit()
Buggy code:
import sys
import itertools
ABCDlist=list(map(int,list(input())))
#print(ABCDlist)

for bit in itertools.product(range(2),repeat=3):
  answer=ABCDlist[0]
  answer_list=[str(answer)]
  for i in range(3):
    if bit[i]==0:
      answer+=ABCDlist[i+1]
      answer_list.append("+"+str(ABCDlist[i+1]))
    else:
      answer-=ABCDlist[i-1]
      answer_list.append("-"+str(ABCDlist[i+1]))
      
  if answer==7:
    answer_list.append("=7")
    print("".join(answer_list))
    sys.exit(0)     

Fixed code:
import sys
import itertools
ABCDlist=list(map(int,list(input())))
#print(ABCDlist)

for bit in itertools.product(range(2),repeat=3):
  answer=ABCDlist[0]
  answer_list=[str(answer)]
  for i in range(3):
    if bit[i]==0:
      answer+=ABCDlist[i+1]
      answer_list.append("+"+str(ABCDlist[i+1]))
    else:
      answer-=ABCDlist[i+1]
      answer_list.append("-"+str(ABCDlist[i+1]))
      
  if answer==7:
    answer_list.append("=7")
    print("".join(answer_list))
    sys.exit(0)
Buggy code:
import itertools
L = list(input())
sm = ['+','-']
SM = list(itertools.product(sm,repeat=3))

for i,j,k in SM:
    if eval(L[0]+i+L[1]+j+L[2]+k+L[3])==7:
        print(L[0]+i+L[1]+j+L[2]+k+L[3]+'=7')


Fixed code:
import itertools
L = list(input())
sm = ['+','-']
SM = list(itertools.product(sm,repeat=3))

for i,j,k in SM:
    if eval(L[0]+i+L[1]+j+L[2]+k+L[3])==7:
        print(L[0]+i+L[1]+j+L[2]+k+L[3]+'=7')
        exit()
Buggy code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

A, B, C, D = map(int, list(input()[:-1]))

n = 3
ops = []
for bit in range(0, 1<<n):
    op = ["-"]*n
    for j in range(n):
        if bit>>j & 1:
            op[j] = "+"
    ops.append(op)

for op in ops:
    a, b, c, d = A, B, C, D
    if op[0] == "-":
        b = -B
    if op[1] == "-":
        c = -C
    if op[2] == "-":
        d = -D
    if a + b + c + d == 7:
        ans = op
        break
ans = str(a)
for num in (b, c, d):
    if num > 0:
        ans += "+"
        ans += str(num)
    else:
        ans += str(num)
ans += "=7"
print(ans)


        

Fixed code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

A, B, C, D = map(int, list(input()[:-1]))

n = 3
ops = []
for bit in range(0, 1<<n):
    op = ["-"]*n
    for j in range(n):
        if bit>>j & 1:
            op[j] = "+"
    ops.append(op)

for op in ops:
    a, b, c, d = A, B, C, D
    if op[0] == "-":
        b = -B
    if op[1] == "-":
        c = -C
    if op[2] == "-":
        d = -D
    if a + b + c + d == 7:
        ans = op
        break
ans = str(a)
for num in (b, c, d):
    if num >= 0:
        ans += "+"
        ans += str(num)
    else:
        ans += str(num)
ans += "=7"
print(ans)
Buggy code:
(a, b, c, d) = map(int, list(input()))
print(a)

if a+b+c+d == 7:
    print(str(a) + '+' + str(b) + '+' + str(c) + '+' + str(d) + '=7')
elif a+b+c-d == 7:
    print(str(a) + '+' + str(b) + '+' + str(c) + '-' + str(d) + '=7')
elif a+b-c+d == 7:
    print(str(a) + '+' + str(b) + '-' + str(c) + '+' + str(d) + '=7')
elif a+b-c-d == 7:
    print(str(a) + '+' + str(b) + '-' + str(c) + '-' + str(d) + '=7')
elif a-b+c-d == 7:
    print(str(a) + '-' + str(b) + '+' + str(c) + '-' + str(d) + '=7')
elif a-b-c+d == 7:
    print(str(a) + '-' + str(b) + '-' + str(c) + '+' + str(d) + '=7')
elif a-b-c-d == 7:
    print(str(a) + '-' + str(b) + '-' + str(c) + '-' + str(d) + '=7')

Fixed code:
(a, b, c, d) = map(int, list(input()))

if a+b+c+d == 7:
    print(str(a) + '+' + str(b) + '+' + str(c) + '+' + str(d) + '=7')
elif a+b+c-d == 7:
    print(str(a) + '+' + str(b) + '+' + str(c) + '-' + str(d) + '=7')
elif a+b-c+d == 7:
    print(str(a) + '+' + str(b) + '-' + str(c) + '+' + str(d) + '=7')
elif a-b+c+d == 7:
    print(str(a) + '-' + str(b) + '+' + str(c) + '+' + str(d) + '=7')
elif a+b-c-d == 7:
    print(str(a) + '+' + str(b) + '-' + str(c) + '-' + str(d) + '=7')
elif a-b+c-d == 7:
    print(str(a) + '-' + str(b) + '+' + str(c) + '-' + str(d) + '=7')
elif a-b-c+d == 7:
    print(str(a) + '-' + str(b) + '-' + str(c) + '+' + str(d) + '=7')
elif a-b-c-d == 7:
    print(str(a) + '-' + str(b) + '-' + str(c) + '-' + str(d) + '=7')
Buggy code:
abcd = input()

op = ['+', '-']

for op1 in op:
    for op2 in op:
        for op3 in op:
            tmp_ans = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3]
            if eval(tmp_ans) == 7:
                print(tmp_ans)
                

Fixed code:
abcd = input()

op = ['+', '-']

for op1 in op:
    for op2 in op:
        for op3 in op:
            tmp_ans = abcd[0] + op1 + abcd[1] + op2 + abcd[2] + op3 + abcd[3]
            if eval(tmp_ans) == 7:
                print(tmp_ans+'=7')
                exit()
Buggy code:
n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])
if a+b+c+d==7:
  print(a+"+"b+"+"+c+"+"+d+"=7")
elif a+b+c-d==7:
  print(a+"+"b+"+"+c+"-"+d+"=7")
elif a+b-c+d==7:
  print(a+"+"b+"-"+c+"+"+d+"=7")
elif a+b-c-d==7:
  print(a+"+"b+"-"+c+"-"+d+"=7")
elif a-b+c+d==7:
  print(a+"-"b+"+"+c+"+"+d+"=7")
elif a-b+c-d==7:
  print(a+"-"b+"+"+c+"-"+d+"=7")
elif a-b-c+d==7:
  print(a+"-"b+"-"+c+"+"+d+"=7")
else:
  print(a+"-"b+"-"+c+"-"+d+"=7")

Fixed code:
n = input()
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])
if a+b+c+d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif a+b+c-d==7:
  print(str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif a+b-c+d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
elif a+b-c-d==7:
  print(str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
elif a-b+c+d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7")
elif a-b+c-d==7:
  print(str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7")
elif a-b-c+d==7:
  print(str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7")
else:
  print(str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7")
Buggy code:
n = list(map(int,input()))

if n[0] + n[1] + n[2] + n[3] == 7:
    print("{}+{}+{}+{}".format(n[0],n[1],n[2],n[3]))
elif n[0] + n[1] + n[2] - n[3] == 7:
    print("{}+{}+{}+{}".format(n[0],n[1],n[2],n[3]))
elif n[0] + n[1] - n[2] + n[3] == 7:
    print("{}+{}+{}+{}".format(n[0],n[1],n[2],n[3]))
elif n[0] + n[1] - n[2] - n[3] == 7:
    print("{}+{}+{}+{}".format(n[0],n[1],n[2],n[3]))
elif n[0] - n[1] + n[2] + n[3] == 7:
    print("{}+{}+{}+{}".format(n[0],n[1],n[2],n[3]))
elif n[0] - n[1] + n[2] - n[3] == 7:
    print("{}+{}+{}+{}".format(n[0],n[1],n[2],n[3]))
elif n[0] - n[1] - n[2] + n[3] == 7:
    print("{}+{}+{}+{}".format(n[0],n[1],n[2],n[3]))
elif n[0] - n[1] - n[2] - n[3] == 7:
    print("{}+{}+{}+{}".format(n[0],n[1],n[2],n[3]))
else:
    print("error")


Fixed code:
n = list(map(int,input()))

if n[0] + n[1] + n[2] + n[3] == 7:
    print("{}+{}+{}+{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] + n[1] + n[2] - n[3] == 7:
    print("{}+{}+{}-{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] + n[1] - n[2] + n[3] == 7:
    print("{}+{}-{}+{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] + n[1] - n[2] - n[3] == 7:
    print("{}+{}-{}-{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] - n[1] + n[2] + n[3] == 7:
    print("{}-{}+{}+{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] - n[1] + n[2] - n[3] == 7:
    print("{}-{}+{}-{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] - n[1] - n[2] + n[3] == 7:
    print("{}-{}-{}+{}=7".format(n[0],n[1],n[2],n[3]))
elif n[0] - n[1] - n[2] - n[3] == 7:
    print("{}-{}-{}-{}=7".format(n[0],n[1],n[2],n[3]))
else:
    print("error")
Buggy code:
#!/usr/bin/env python3
N = input()

for i in range(8):
    num = [int(i) for i in N]
    for j in range(3):
        if (i >> j) % 2 == 1:
            num[j] *= -1
    if sum(num) == 7:
        print('{:d}{:+d}{:+d}{:+d}=7'.format(num[0], num[1], num[2], num[3]))
        break


Fixed code:
#!/usr/bin/env python3
N = input()

for i in range(8):
    num = [int(i) for i in N]
    for j in range(3):
        if (i >> j) % 2 == 1:
            num[-j - 1] *= -1
    if sum(num) == 7:
        print('{:d}{:+d}{:+d}{:+d}=7'.format(num[0], num[1], num[2], num[3]))
        break
Buggy code:
s = list(input())
op = ['+', '-']
for op1 in op:
    for op2 in op:
        for op3 in op:
            ans = s[0]+op1+s[1]+op2+s[2]+op3+s[3]
            if eval(ans) ==7:
                print(ans + '=7')
                break

Fixed code:
s = list(input())
op = ['+', '-']
for op1 in op:
    for op2 in op:
        for op3 in op:
            ans = s[0]+op1+s[1]+op2+s[2]+op3+s[3]
            if eval(ans) ==7:
                print(ans + '=7')
                exit()
Buggy code:
a, b, c, d = map(int, list(input()))
if a+b+c+d == 7: print(a,"+", b, "+", c, "+", d, sep="")
elif a+b+c-d == 7: print(a,"+", b, "+", c, "-", d, sep="")
elif a+b-c+d == 7: print(a,"+", b, "-", c, "+", d, sep="")
elif a-b+c+d == 7: print(a,"-", b, "+", c, "+", d, sep="")
elif a+b-c-d == 7: print(a,"+", b, "-", c, "-", d, sep="")
elif a-b-c+d == 7: print(a,"-", b, "-", c, "+", d, sep="")
elif a-b+c-d == 7: print(a,"-", b, "+", c, "-", d, sep="")
else: print(a,"-", b, "-", c, "-", d, sep="")1222

Fixed code:
a, b, c, d = map(int, list(input()))
if a+b+c+d == 7: print(a,"+", b, "+", c, "+", d, "=7", sep="")
elif a+b+c-d == 7: print(a,"+", b, "+", c, "-", d, "=7", sep="")
elif a+b-c+d == 7: print(a,"+", b, "-", c, "+", d, "=7", sep="")
elif a-b+c+d == 7: print(a,"-", b, "+", c, "+", d, "=7", sep="")
elif a+b-c-d == 7: print(a,"+", b, "-", c, "-", d, "=7", sep="")
elif a-b-c+d == 7: print(a,"-", b, "-", c, "+", d, "=7", sep="")
elif a-b+c-d == 7: print(a,"-", b, "+", c, "-", d, "=7", sep="")
else: print(a,"-", b, "-", c, "-", d, "=7", sep="")
Buggy code:
S = input()

op = ["+","-"]

for a in op:
  for b in op:
    for c in op:
      shiki = S[0]+a+S[1]+b+S[2]+c+S[3]+"==7"
      if eval(shiki):
        print(shiki)
        exit()

Fixed code:
S = input()

op = ["+","-"]

for a in op:
  for b in op:
    for c in op:
      shiki = S[0]+a+S[1]+b+S[2]+c+S[3]
      if eval(shiki)==7:
        print(shiki+"=7")
        exit()
Buggy code:
A,B,C,D=list(input())

F=["+","-"]

for x in range(2):
    for y in range(2):
        for z in range(2):
            if eval(A+F[x]+B+F[y]+C+F[z]+D)==7:
                print(A+F[x]+B+F[y]+C+F[z]+D+"=7")

Fixed code:
A,B,C,D=list(input())

F=["+","-"]

for x in range(2):
    for y in range(2):
        for z in range(2):
            if eval(A+F[x]+B+F[y]+C+F[z]+D)==7:
                print(A+F[x]+B+F[y]+C+F[z]+D+"=7")
                exit()
Buggy code:
A = [int(v) for v in input()]

flag = False
for i in range(2):
  if flag:
    break
  total = A[0]
  if i == 0:
    total += A[1]
  else:
    total -= A[1]
  for j in range(2):
    if flag:
      break
    if j == 0:
      total += A[2]
    else:
      total -= A[2]
    for k in range(2):      
      if k == 0:
        total += A[3]
      else:
        total -= A[3]
      if total == 7:
        print(A[0], end='')
        if i == 0:
          print('+{}'.format(A[1]), end='')
        else:
          print('-{}'.format(A[1]), end='')
        if j == 0:
          print('+{}'.format(A[2]), end='')
        else:
          print('-{}'.format(A[2]), end='')
        if k == 0:
          print('+{}=7'.format(A[3]))
        else:
          print('-{}=7'.format(A[3]))
        flag = True
        break

Fixed code:
A = [int(v) for v in input()]

flag = False
for i in range(2):
  if flag:
    break
  total = A[0]
  if i == 0:
    total += A[1]
  else:
    total -= A[1]
  for j in range(2):
    if flag:
      break
    total2 = total
    if j == 0:
      total2 += A[2]
    else:
      total2 -= A[2]
    for k in range(2):
      total3 = total2
      if k == 0:
        total3 += A[3]
      else:
        total3 -= A[3]
      if total3 == 7:
        print(A[0], end='')
        if i == 0:
          print('+{}'.format(A[1]), end='')
        else:
          print('-{}'.format(A[1]), end='')
        if j == 0:
          print('+{}'.format(A[2]), end='')
        else:
          print('-{}'.format(A[2]), end='')
        if k == 0:
          print('+{}=7'.format(A[3]))
        else:
          print('-{}=7'.format(A[3]))
        flag = True
        break
Buggy code:
import itertools
A, B, C, D = list(input())

op = ['+','-']

for a,b,c in itertools.product(op,op,op):
  x = A + op1 + B + op2 + C + op3 + D
  if(eval(x) == 7):
    print(x + "=7")
    break

Fixed code:
import itertools
A, B, C, D = list(input())

op = ['+','-']

for op1,op2,op3 in itertools.product(op,op,op):
  x = A + op1 + B + op2 + C + op3 + D
  if(eval(x) == 7):
    print(x + "=7")
    break
Buggy code:
abcd = input()
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])

ans_list = [[0 for _ in range(8)] for __ in range(3)]

ans_list[0][0] = a + b
ans_list[0][1] = a - b
for i in range(2):
    ans_list[1][i * 2] = ans_list[0][i] + c
    ans_list[1][i * 2 + 1] = ans_list[0][i] - c
for i in range(4):
    ans_list[2][i * 2] = ans_list[1][i] + d
    ans_list[2][i * 2 + 1] = ans_list[1][i] - d

for n in range(8):
    if ans_list[2][n] == 7:
        ans = ""
        ans += abcd[0]
        if n > 4:
            ans += "-"
        else:
            ans += "+"
        ans += abcd[1]
        if n == 0 or n == 1 or n == 4 or n == 5:
            ans += "+"
        else:
            ans += "-"
        ans += abcd[2]
        if n % 2 == 0:
            ans += "+"
        else:
            ans += "-"
        ans += abcd[3]
        ans += "=7"
        print(ans)
        break

Fixed code:
abcd = input()
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])

ans_list = [[0 for _ in range(8)] for __ in range(3)]

ans_list[0][0] = a + b
ans_list[0][1] = a - b
for i in range(2):
    ans_list[1][i * 2] = ans_list[0][i] + c
    ans_list[1][i * 2 + 1] = ans_list[0][i] - c
for i in range(4):
    ans_list[2][i * 2] = ans_list[1][i] + d
    ans_list[2][i * 2 + 1] = ans_list[1][i] - d

for n in range(8):
    if ans_list[2][n] == 7:
        ans = ""
        ans += abcd[0]
        if n > 3:
            ans += "-"
        else:
            ans += "+"
        ans += abcd[1]
        if n == 0 or n == 1 or n == 4 or n == 5:
            ans += "+"
        else:
            ans += "-"
        ans += abcd[2]
        if n % 2 == 0:
            ans += "+"
        else:
            ans += "-"
        ans += abcd[3]
        ans += "=7"
        print(ans)
        break
Buggy code:

A,B,C,D = input()
A = int(A)
B = int(B)
C = int(C)
D = int(D)
sum = 0
ope = ["", "",""]
for i in range(2):

    for j in range(2):

        for k in range(2):
            if (i == 0):
                sum += A + B
                ope[0] = "+"
            if (i == 1):
                sum += A - B
                ope[0] = "-"
            if (j == 0):
                sum += C
                ope[1] = "+"
            if (j == 1):
                sum -= C
                ope[1] = "-"
            if (k == 0):
                sum += D
                ope[2] = "+"
                if (sum == 7):
                    break
            if(k==1):
                sum -= D
                ope[2] = "-"
                if (sum == 7):
                    break
        if (sum == 7):
            break
        else:
            sum=0
    if (sum == 7):
        break
print("{}{}{}{}{}{}{}=7".format(A,ope[0],B,ope[1],C,ope[2],D))

Fixed code:

A,B,C,D = input()
A = int(A)
B = int(B)
C = int(C)
D = int(D)
sum = 0
ope = ["", "",""]
for i in range(2):

    for j in range(2):

        for k in range(2):
            if (i == 0):
                sum += A + B
                ope[0] = "+"
            if (i == 1):
                sum += A - B
                ope[0] = "-"
            if (j == 0):
                sum += C
                ope[1] = "+"
            if (j == 1):
                sum -= C
                ope[1] = "-"
            if (k == 0):
                sum += D
                ope[2] = "+"
                if (sum == 7):
                    break
                else:
                    sum = 0
            if(k==1):
                sum -= D
                ope[2] = "-"
                if (sum == 7):
                    break
                else:
                    sum = 0
        if (sum == 7):
            break

    if (sum == 7):
        break
print("{}{}{}{}{}{}{}=7".format(A,ope[0],B,ope[1],C,ope[2],D))
Buggy code:
s = input()
num_digits = len(s)


def dfs(index, formula, sum_number):
    if index + 1 == num_digits:
        if sum_number == 7:
            print(formula + "=7")
            exit()
    else:
        dfs(index + 1, formula + "+" + s[index + 1], sum_number + int(s[index + 1]))
        dfs(index + 1, formula + "-" + s[index + 1], sum_number - int(s[index + 1]))


print(dfs(0, s[0], 0))


Fixed code:
s = input()
num_digits = len(s)


def dfs(index, formula, sum_number):
    if index + 1 == num_digits:
        if sum_number == 7:
            print(formula + "=7")
            exit()
    else:
        dfs(index + 1, formula + "+" + s[index + 1], sum_number + int(s[index + 1]))
        dfs(index + 1, formula + "-" + s[index + 1], sum_number - int(s[index + 1]))


print(dfs(0, s[0], int(s[0])))
Buggy code:
N=input()
a,b,c,d=int(N[0]),int(N[1]),int(N[2]),int(N[3])

if a+b+c+d==7 : print("{0}+{1}+{2}+{3}=7".format(a,b,c,d))
if a+b+c-d==7 : print("{0}+{1}+{2}-{3}=7".format(a,b,c,d))
if a+b-c+d==7 : print("{0}+{1}-{2}+{3}=7".format(a,b,c,d))
if a+b-c-d==7 : print("{0}+{1}-{2}-{3}=7".format(a,b,c,d))
if a-b+c+d==7 : print("{0}-{1}+{2}+{3}=7".format(a,b,c,d))
if a-b+c-d==7 : print("{0}-{1}+{2}-{3}=7".format(a,b,c,d))
if a-b-c+d==7 : print("{0}-{1}-{2}+{3}=7".format(a,b,c,d))
if a-b-c-d==7 : print("{0}-{1}-{2}-{3}=7".format(a,b,c,d))

Fixed code:
N=input()
a,b,c,d=int(N[0]),int(N[1]),int(N[2]),int(N[3])

if a+b+c+d==7 : print("{0}+{1}+{2}+{3}=7".format(a,b,c,d))
elif a+b+c-d==7 : print("{0}+{1}+{2}-{3}=7".format(a,b,c,d))
elif a+b-c+d==7 : print("{0}+{1}-{2}+{3}=7".format(a,b,c,d))
elif a+b-c-d==7 : print("{0}+{1}-{2}-{3}=7".format(a,b,c,d))
elif a-b+c+d==7 : print("{0}-{1}+{2}+{3}=7".format(a,b,c,d))
elif a-b+c-d==7 : print("{0}-{1}+{2}-{3}=7".format(a,b,c,d))
elif a-b-c+d==7 : print("{0}-{1}-{2}+{3}=7".format(a,b,c,d))
elif a-b-c-d==7 : print("{0}-{1}-{2}-{3}=7".format(a,b,c,d))
Buggy code:
def main():
	n = [int(i) for i in input()]
	for i in range(7):
		x2 = base_10_to_n(i,2)
		for _ in range(3-len(x2)):	
			x2 = '0' + x2
		ans = n[0]
		for j in range(3):
			if(x2[j] == '0'):
				ans += n[j+1]
			else:
				ans -= n[j+1]
		if(ans == 7):
			text = str(n[0])
			for j in range(3):
				if(x2[j] == '0'):
					text = text + '+' + str(n[j+1])
				else:
					text = text + '-' + str(n[j+1])
			print(text+'=0')
			return 0

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Fixed code:
def main():
	n = [int(i) for i in input()]
	for i in range(7):
		x2 = base_10_to_n(i,2)
		for _ in range(3-len(x2)):	
			x2 = '0' + x2
		ans = n[0]
		for j in range(3):
			if(x2[j] == '0'):
				ans += n[j+1]
			else:
				ans -= n[j+1]
		if(ans == 7):
			text = str(n[0])
			for j in range(3):
				if(x2[j] == '0'):
					text = text + '+' + str(n[j+1])
				else:
					text = text + '-' + str(n[j+1])
			print(text+'=7')
			return 0

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()
Buggy code:
# -*- coding: utf-8 -*-

a, b, c, d = map(str, input())

sign = "+-"
for i in range(2):
    for j in range(2):
        for k in range(2):
            if int(eval(a+sign[i]+b+sign[j]+c+sign[k]+d)) == 7:
                print(str(a+sign[i]+b+sign[j]+c+sign[k]+d)+"=7")

Fixed code:
# -*- coding: utf-8 -*-

a, b, c, d = map(str, input())

sign = "+-"
for i in range(2):
    for j in range(2):
        for k in range(2):
            if int(eval(a+sign[i]+b+sign[j]+c+sign[k]+d)) == 7:
                print(str(a+sign[i]+b+sign[j]+c+sign[k]+d) + "=7")
                exit()