Stuck in Arithmetic Formatter

Tell us what’s happening:
I’m still getting all the errors.
Can someone help find the bug?

Your code so far


def arithmetic_arranger(problems, answer=False):
    if len(problems) > 5:
        return "Error: Too many problems"

    dashes = ""
    top_row = ""
    bottom_row = ""
    sum_row = ""
    for problem in problems:
        prob = problem.split()
        x = prob[0]
        y = prob[1]
        z = prob[2]

        if len(x) > 4 or len(z) > 4:
            return ("Error: Numbers cannot be more than four digits.")
        if not x.isnumeric() or not z.isnumeric():
            return ("Error: Numbers must only contain digits.")
        if y == "+" or y == "-":
            if y == "+":
                r = int(x) + int(z)
            elif y == "-":
                r = int(x) - int(z)

            length = max(len(x), len(z)) + 2
            top = str(x).rjust(length)
            bottom = y + str(z).rjust(length - 1)
            sum = str(r).rjust(length)
            dash = ""
            for d in range(length):
                dash += '-'
            top_row += top + "    "
            bottom_row += bottom + "    "
            dashes += dash + "    "
            sum_row += sum + "    "

        else:
            return ("Error: Operator must be '+' or '-'.")
    
    top_row.rstrip()
    bottom_row.rstrip()
    dashes.rstrip()
    sum_row.rstrip()

    if answer is False:
        arranged_problems = top_row + "\n" + bottom_row + "\n" + dashes
    elif answer is True:
        arranged_problems = top_row + "\n" + bottom_row + "\n" + dashes + "\n" + sum_row

    return arranged_problems

ERRORS:

python main.py
   32      3801      45      123    
+ 698    -    2    + 43    +  49    
-----    ------    ----    -----    
F..F.F
======================================================================
FAIL: test_arrangement (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-arithmetic-formatter-4/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: '    [23 chars]  123    \n+ 855    -    2    + 43    +  49   [35 chars]    ' != '    [23 chars]  123\n+ 855    -    2    + 43    +  49\n-----[23 chars]----'
-     3      3801      45      123    
?                                 ----
 python main.py
   32      3801      45      123    
+ 698    -    2    + 43    +  49    
-----    ------    ----    -----    
F..F.F
======================================================================
FAIL: test_arrangement (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-arithmetic-formatter-4/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: '    [23 chars]  123    \n+ 855    -    2    + 43    +  49   [35 chars]    ' != '    [23 chars]  123\n+ 855    -    2    + 43    +  49\n-----[23 chars]----'
-     3      3801      45      123    
?                                 ----
+     3      3801      45      123
- + 855    -    2    + 43    +  49    
?                                 ----
+ + 855    -    2    + 43    +  49
- -----    ------    ----    -----    ?                                 ----
+ -----    ------    ----    ----- : Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]

======================================================================
FAIL: test_solutions (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-arithmetic-formatter-4/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 arithmetic problems and a second argument of `True`.')
AssertionError: '   3[23 chars]  123    \n- 698    - 3801    + 43    +  49   [73 chars]    ' != '   3[23 chars]  123\n- 698    - 3801    + 43    +  49\n-----[57 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 arithmetic problems and a second argument of `True`.

======================================================================
FAIL: test_too_many_problems (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-arithmetic-formatter-4/test_module.py", line 19, in test_too_many_problems
    self.assertEqual(actual, expected, 'Expected calling "arithmetic_arranger()" with more than five problems to return "Error: Too many problems."')
AssertionError: 'Error: Too many problems' != 'Error: Too many problems.'
- Error: Too many problems
+ Error: Too many problems.
?                         +
 : Expected calling "arithmetic_arranger()" with more than five problems to return "Error: Too many problems."

----------------------------------------------------------------------
Ran 6 tests in 0.004s

FAILED (failures=3)

Challenge: Arithmetic Formatter

what do you get as errors? can you post them?

Yes, sorry i forgot to paste the errors, I edited now

this is the easy one
you are missing a character in your output string


yo7u have extra characters (spaces) at the end of each line

Great!
thanks i got it now.
i think it was just a bit difficult to see the errors, but as you put it in red and green was much easier haha

thanks!