 # Arithmetic Arranger Test Failure

I have been testing this arithmetic arranger project for the first scientific computing with python project and every time I enter one of the test inputs into the code it comes out identical to the expected output. Despite this, I keep receiving a single failure. I searched to see if anyone else had a similar problem and a solution, but I did not see one.

Here is my code:

``````def arithmetic_arranger(problems, showAns = False):
int_1_line = ""
int_2_line = ""
line_line = ""
if len(problems) > 5:
return "Error: Too many problems."
else:
for problem in problems:
int_1_end = problem.find(" ")
int_1 = (problem[0:int_1_end])

operator_end = int_1_end + 2
operator = (problem[int_1_end+1:operator_end])

int_2_end = problem[len(problem)- 1]
int_2 = (problem[operator_end+1:-1])
int_2 = int_2 + problem[-1]

if operator not in ["+", "-"]:
return "Error: Operator must be '+' or '-'."
elif isinstance(int(int_2), int) != True or isinstance(int(int_2), int) != True:
return "Error: Numbers must only contain digits."
elif len(int_1) > 4 or len(int_2) > 4:
return "Error: Numbers cannot be more than four digits."
else:

if operator in ["+"]:
elif operator in ["-"]:
else:
return  "Error: Operator must be '+' or '-'."

big_int = max(len(str(int_1)),len(str(int_2)))
width = big_int + 2

int_1_line = int_1_line + "    " + (int_1.rjust(width))

int_2_line = int_2_line + "    " + (operator + (int_2.rjust(width-1)))

line = "-"*(width)
line_line += "    " + line

if showAns == True:

int_1_done = int_1_line[4:]
int_2_done = int_2_line[4:]
line_done = line_line[4:]
arranged_problems = int_1_done + "\n" + int_2_done + "\n" + line_done + "\n" + answer_done
return arranged_problems
``````

looking at this: it seems you have an extra space at the end of last line

Thank you for pointing that out for me. I’ve tried slicing part of the string and using .rstrip(), but the error is still occurring.

Hello~!

It looks like you have a line-break `\n` after your line of dashes.

Thank you so much, I have no clue how I didn’t realize that would be a problem if the answers weren’t being printed. The code is working fine now with no errors.

1 Like