Help in the arithmetic formatter

def arithmetic_arranger(problems, result =False):
first =’’
second =’’
third =’’
sol =’’
n=’’
arranged_problems =’’
if len(problems) < 5:
for x in problems:
y = x.split(" ")

``````        try:
a = int(y[0])
b = int(y[2])
except ValueError:
return ("Error: Numbers must only contain digits.")

if a<=9999 and b<=9999:
pass
else:
return ("Error: Numbers cannot be more than four digits.")
exit()

if y[1] not in ['+','-']:
return "Error: Operator must be '+' or '-'."
if a>b:
z = len(y[0]) +2
n = '-'*z
if len(y[2]) == 1:
space1 = " "*(len(y[0]))
first += f"  {y[0]}    "
second+= f"{y[1]}{space1}{y[2]}    "
elif len(y[2]) == 2:
space1 = " " * (len(y[0])-1 )
first += f"  {y[0]}    "
second += f"{y[1]}{space1}{y[2]}    "
elif len(y[2]) == 3:
space1 = " " * (len(y[2]) -2)
first += f"  { y[0]}    "
second += f"{y[1]}{space1}{y[2]}    "
elif len(y[2]) == 4:
space1 = " "
first += f"  { y[0]}    "
second += f"{y[1]}{space1}{y[2]}    "
else:
z=len(y[2]) +2
n="-"*z
if len(y[0]) == 1:
space1 = " "*(len(y[2])+1)
first += f"{space1}{y[0]}    "
second+= f"{y[1]} {y[2]}    "
elif len(y[0]) == 2:
space1 = " " * (len(y[2]) )
first += f"{space1}{y[0]}    "
second += f"{y[1]} {y[2]}    "
elif len(y[0]) == 3:
space1 = " " * (len(y[2]) -1)
first += f"{space1}{y[0]}    "
second += f"{y[1]} {y[2]}    "
elif len(y[0]) == 4:
space1 = " " * 2
first += f"{space1}{y[0]}    "
second += f"{y[1]} {y[2]}    "
third+=f"{n}    "
if eval(x) <0:
sol+=f" {eval(x)}    "
else:
sol+=f"  {eval(x)}    "
else:
return "Error: Too many problems."
if result==True:
arranged_problems =f"{first}\b\b\b\b\n{second}\b\b\b\b\n{third}\b\b\b\b\n{sol}\b\b\b"
else:
arranged_problems = f"{first}\b\b\b\b\n{second}\b\b\b\b\n{third}\b\b\b\b"
``````- your output