# Help arithmmetic formatter

Tell us what’s happening:
Thanks.

def arithmetic_arranger(problems, solve=False):
firstLine = “”
secondLine = “”
space = " "
dashes = “”

``````solution = ""
solvedSum = ""

if len(problems) > 5:
return "Error: Too many problems."
for problem in problems:
first = problem.split(" ")
operator = problem.split(" ")
second = problem.split(" ")
if (len(first) > 4 or len(second) > 4):
return "Error: Numbers cannot be more than four digits."
if not operator in ["+", "-"]:
return "Error: Operator must be '+' or '-'."
if not first.isdigit() or not second.isdigit():
return "Error: Numbers must only contain digits."
else:
MaxLength = max(len(first),len(second))
firstLine += first.rjust(MaxLength+2)
secondLine += operator + second.rjust(MaxLength+1)

for i in range(MaxLength):
dashes += "-"
if solve == True:
if operator == "+":
solvedSum = str(int(first) + int(second))
else:
solvedSum = str(int(first) - int(second))
solution = str((solvedSum).rjust(MaxLength+2))
finalResult = space + firstLine.rstrip() + "\n" + secondLine.rstrip() + "\n" + dashes.rstrip() + space
arranged_problems = finalResult + "\n" + solvedSum.rstrip() if solve else finalResult

return arranged_problems
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36`.