I'm stuck in arithmetic formatter :(

I try anyway i can to do this. But it doesn’t work

def arithmetic_arranger(*problems):
    count = 0;
  
    tops = ""
    bottoms = ""
    operators = ""
    sums = ""
    for problem in problems[0]:
        #print(problem)
        count += 1

        #print("count  " + str(count))
        if(count > 5): return "Error: Too many problems."
        cutProblems = problem.split()
        #print(math.isnan (float(cutProblems[0])))
        if (cutProblems[0].isnumeric() and cutProblems[2].isnumeric()):
            a = cutProblems[0]
            b = cutProblems[2]
            op = cutProblems[1]
            if( int(a) >= 10000 or int(b) >= 10000): return "Error: Numbers cannot be more than four digits."
            if op == "+" or op == "-": 
                #x.append(a + b)
                if op == "+": final = int(a) + int(b)
                elif op == "-": final = int(a) - int(b) 
                length = max(len(a), len(b)) + 2
                top = a.rjust(length)
                bottom = op + b.rjust(length - 1)
                
                operator = ""
                operator = operator.rjust(length, "-")
                sum = str(final).rjust(length)

                tops += top + "    "
                bottoms += bottom + "    "
                operators += operator + "    "
                sums += sum + "    "
            else: return "Error: Operator must be '+' or '-'."
        else: return "Error: Numbers must only contain digits."
    tops.rstrip()
    bottoms.rstrip()
    operators.rstrip()
    sums.rstrip()
    if(len(problems) > 1 and problems[1] == True):
        arithmetic_problems = tops + "\n" + bottoms + "\n" + operators + "\n" + sums
    else: arithmetic_problems = tops + "\n" + bottoms + "\n" + operators + "\n" 
    return arithmetic_problems

and this is result

FAIL: test_arrangement (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-arithmetic-formatter-2/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   [37 chars]  \n' != '    [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-2/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`.

----------------------------------------------------------------------
Ran 6 tests in 0.052s

this is my first time posting so please ignore it if it’s missing

Hello there.

Do you have a question?

If so, please edit your post to include it.

The more information you give us, the more likely we are to be able to help.

i have just update :frowning:

1 Like

this is showing that there is a difference between your output and the expected one at the end of each line

This post was flagged by the community and is temporarily hidden.

This is false. The code is largely correct.

i totaly agree brother anyway here we go i try to help again but the modes flaged me i won’t jump again