# Arithmetic Formatter: Error in testing modul without a reason

Hey, when I try to run the testing modul I get two erorrors: “Expected solutions to be correctly displayed in output when calling “arithmetic_arranger()”” (test_solutions) and “Expected different output when calling “arithmetic_arranger()”” (test_arrangement).
I can’t find my mistake, when I ran the problems in my terminal I get the correct answer.
I compared them side-by-side:

Output of my personal Terminal: (First: Asked solution (just copy-pasted in print() Second: the output of my def)

``````   32         1      45      123
- 698    - 3801    + 43    +  49
-----    ------    ----    -----
-666     -3800      88      172
``````
``````   32         1      45      123
- 698    - 3801    + 43    +  49
-----    ------    ----    -----
-666     -3800      88      172
``````
``````def arithmetic_arranger(problems,answer = None):
length = len(problems)

if length > 5:
return "Error: Too many problems."

exercice = list()
for i in range(length):
exercice.append(problems[i].split())

number1 = list()
for i in range(length):
number1.append(exercice[i][0])
try:
number1[i]= int(number1[i])
number1[i]= str(number1[i])
except:
return "Error: Number must only contain digits"

number2 = list()
for i in range(length):
number2.append(exercice[i][2])
try:
number2[i]= int(number2[i])
number2[i]= str(number2[i])
except:
return "Error: Number must only contain digits."

sign = list()
for i in range(length):
sign.append(exercice[i][1])

ans = list()
for i in range(length):
if sign[i] == "+":
ans.append(str(int(number1[i]) + int(number2[i])))
elif sign[i] == "-":
ans.append(str(int(number1[i]) - int(number2[i])))
else:
return "Error: Operator must be '+' or '-'."

len1 = list()
for i in range(length):
len1.append(len(number1[i]))
if len1[i] > 4:
return "Error: Numbers cannot be more than four digits."

len2 = list()
for i in range(length):
len2.append(len(number2[i]))
if len2[i] > 4:
return "Error: Numbers cannot be more than four digits."

lena = list()
for i in range(length):
lena.append(len(ans[i]))

line1 = ""
for i in range(length):
if len1[i] > len2[i]:
line1 = line1 + "  " + number1[i]
elif len1[i] < len2[i]:
line1 = line1 + "  " + (len2[i] - len1[i])*" " + number1[i]
elif len1[i] == len2[i]:
line1 = line1 + "  "+ number1[i]
line1 = line1 + 4* " "

line2 = ""
for i in range(length):
line2 = line2 + sign[i]
if len2[i] > len1[i]:
line2 = line2 + " " + number2[i]
elif len2[i] < len1[i]:
line2 = line2 + " " + (len1[i] - len2[i])*" " + number2[i]
elif len1[i] == len2[i]:
line2 = line2 + " " + number2[i]
line2 = line2 + 4* " "

line3 = ""
for i in range(length):
line3 = line3 + "--" + max(len1[i],len2[i])*"-"
line3 = line3 + 4*" "

line4 = ""
for i in range(length):
if lena[i] == max(len1[i],len2[i]):

line4 = line4 + "  " + ans[i]
elif lena[i] < max(len1[i],len2[i]):

line4 = line4 + "  " + (max(len1[i],len2[i])-lena[i])* " " + ans[i]
elif lena[i] > max(len1[i],len2[i]):

line4 = line4 + " " + ans[i]
line4 = line4 + 4*" "

if answer is None:
result = line1 + "\n" + line2 + "\n" + line3
elif answer is True:
result = line1 + "\n" + line2 + "\n" + line3 + "\n" + line4
return result
``````

Your browser information:

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

Challenge: Arithmetic Formatter

Link to the challenge:

can you post the output of the tests? that’s a good place to start to figure out what’s going on

1 Like

Hey i found my problem. I added to much space. But thx

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.