# Stuck with Arithmetic Formatter

Hi, I always get these errors but I dont know why.

``````def arithmetic_arranger(problems, answer=False):
arranged_problems = ""
upper_line = ""
lower_line = ""
dash_line = ""
result_line = ""

#If there are too many problems supplied to the function. The limit is five, anything more will return an Error
if len(problems) >= 6:
return "Error: Too many problems."

for problem in problems:

left_operand, operator, right_operand = problem.split()

# The appropriate operators the function will accept are addition and subtraction. Multiplication and division will return an error
if operator != "+" and operator != "-":
return "Error: Operator must be '+' or '-'."

# Each number (operand) should only contain digits
if not left_operand.isdigit() or not right_operand.isdigit:
return "Error: Numbers must only contain digits."

#Each operand has a max of four digits in width
if len(left_operand) > 4 or len(right_operand) > 4:
return "Error: Numbers cannot be more than four digits."

# Calculates the answer of the problem
if operator == "+":
sum = str(int(left_operand) + int(right_operand))
else:
sum = str(int(left_operand) - int(right_operand))

# Adds the single parts to their place in the string
length = max(len(left_operand), len(right_operand))
upper_line += str(left_operand.rjust(length + 2)) + "    "
lower_line += str(operator + " " + right_operand.rjust(length)) + "    "
dash_line += str("-" * (length + 2))  + "    "
result_line += str(sum).rjust(length + 2) + "    "

arranged_problems += upper_line + "\n" + lower_line + "\n" + dash_line + "\n" + result_line
else:
arranged_problems += upper_line + "\n" + lower_line + "\n" + dash_line

return arranged_problems
``````
``````python main.py
32         1      45      123
- 698    - 3801    + 43    +  49
-----    ------    ----    -----
F.EF..
======================================================================
ERROR: test_only_digits (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-arithmetic-formatter-1/test_module.py", line 32, in test_only_digits
actual = arithmetic_arranger(["98 + 3g5", "3801 - 2", "45 + 43", "123 + 49"])
File "/home/runner/boilerplate-arithmetic-formatter-1/arithmetic_arranger.py", line 31, in arithmetic_arranger
sum = str(int(left_operand) + int(right_operand))
ValueError: invalid literal for int() with base 10: '3g5'

======================================================================
FAIL: test_arrangement (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-arithmetic-formatter-1/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-1/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: '   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 arithemetic problems and a second argument of `True`.

----------------------------------------------------------------------
Ran 6 tests in 0.007s

FAILED (failures=2, errors=1)
 ^C
 ^C

``````

What is this string doing here?
I guess, you edited it by mistake.

You’re adding extra space after adding each number from the problem list, also for the last problem.
Therefore, you’re having extra spaces at end of each line

I dont think i edited it. Isnt it supposed to be there?

How Can i solve the problem ?

it seems you are not returning the appropriate error here and instead the code is trying to parse `3g5` as an integral

But where is the Problem in my error detection

check if this is working as intended, try debugging

I Tested it and it worked. Idk Whats the Problem but thx

Ohk, So maybe it’s part of the test…
Have you tested your function which checks, if the problems are numerical?

Yeah i tested it and i got the correct error message

can you give the link to your repl?

why ? And i fixed the problem with the spaces at the end, but i still got the error problem

to see what the errors say, to see what’s wrong

Nvm i found the Problem. I forgot a () behind isdigit…