Python: Arithmetic Formatter (Help, 2 failures)

def arithmetic_arranger(test_lst, solve = False):

  # Test so that number of problems is not more than 5
  if(len(test_lst) > 5):
    return 'Error: Too many problems.'
  else:
    pass
  # Variables to store the full strings (the ones to return)
  top = ''
  den = ''
  line = ''
  ans = ''

  for x in test_lst:
    temp = x.split()
    first = temp[0]
    operand = temp[1]
    second = temp[2]
    temp_ans = ''

    if (operand not in ['-', '+']):
      return "Error: Operator must be '+' or '-'."
    else:
      pass

    if (len(first) > 4 or len(second) > 4):
      return "Error: Numbers cannot be more than four digits."
    else:
      pass
    if (solve and (operand == '+' or operand == '-')):
      if(operand == '+'):
        temp_ans = str(int(first)+int(second))
      else:
        temp_ans = str(int(first)-int(second))
    elif(solve):
      return "Error: Operator must be '+' or '-'."
    else:
      pass
    if (not first.isnumeric() or not second.isnumeric()):
      return "Error: Numbers must only contain digits."
    else:
      pass

    # Put together string and adjust spaces
    line_len = max(len(first), len(second)) + 2
    first = first.rjust(line_len)
    second = second.rjust(line_len-1)
    temp_ans = temp_ans.rjust(line_len)
    if (x != test_lst[-1]):
      line += '-'*line_len + '     '
      ans += temp_ans + '     '
      top += first + '     '
      den += operand + second + '     '
    else:
      line += '-'*line_len
      ans += temp_ans
      top += first
      den += operand + second
  arrenged_problems = top+'\n'+den+'\n'+line+'\n'+ans+'\n'
  return arrenged_problems

Works fine when running in terminal on computer. But test complains over 2 failures.

1:
Expected solutions to be correctly displayed in output when calling “arithmetic_arranger()” with arithemetic problems and a second argument of True

2:
Expected different output when calling “arithmetic_arranger()” with [“3 + 855”, “3801 - 2”, “45 + 43”, “123 + 49”]

if you call the function for this test, what do you get as output?

Traceback (most recent call last):
  File "/home/runner/boilerplate-arithmetic-formatter/test_module.py", line 39, in test_solutions
    self.assertEqual(actual, expected, 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with arithemetic problems and a second argument of `True`.')
AssertionError: '   32          1       45       123\n- 698     - 3801  [87 chars] 172' != '   32         1      45      123\n- 698    - 3801    + [75 chars] 172'
-    32          1       45       123
?               - -        -
+    32         1      45      123
- - 698     - 3801     + 43     +  49
?          -          -        -
+ - 698    - 3801    + 43    +  49
- -----     ------     ----     -----
?      -              -    -
+ -----    ------    ----    -----
-  -666      -3800       88       172?      -                -  -
+  -666     -3800      88      172 : Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with arithemetic problems and a second argument of `True`.

Thanks for taking the time!

here it’s shown the differential result: the lines starting with - are from your output and the lines starting with + are what the output should be, the lines starting with ? show the difference between the two

you have some extra characters around

Thanks alot! This helped!

This failure is a little curious for me. How come this is wrong?

Traceback (most recent call last):
  File "/home/runner/boilerplate-arithmetic-formatter/test_module.py", line 10, in test_arrangement
    self.assertEqual(actual, expected, 'Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]')
AssertionError: '    [68 chars]-    ------    ----    -----\n                                ' != '    [68 chars]-    ------    ----    -----'
      3      3801      45      123
  + 855    -    2    + 43    +  49
- -----    ------    ----    -----
?                                 -
+ -----    ------    ----    ------                                  : Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]

As I read it, the test wants to have a total of 6 lines at the final problem, but the total length of the largest of the 2 strings that makes up the output is 5. How could this be?

that’s weird, but it’s not an extra dash there that it wants
the issue is the \n at the end of your output

tthe first is yours (a line break and a lot of space at the end) the second is the expected (it ends with 5 dashes)

there is some bug with the diff part it seems

That is unsettling, thanks for the help tho! I really appreciate it!