# Scientific Computing with Python Projects - Arithmetic Formatter

Tell us what’s happening:
Assertion error when running code against tests. Even though when testing string outputs are the same as the expected outputs in the testing file.

``````def arithmetic_arranger(problems, *args):

#problems = (['32 - 698', '1 - 3801', '45 + 43', '123 + 49', '988 + 40'])
number1 = 0
number2 = 0
operand = ""
line1 = ""
line2 = ""
line3 = ""
line4 = ""
spaces = 0
indent = "   "
sumx = 0

if len(problems) > 5:
return"Error: Too many problems."

#array split into seperate numbers and operators
for item in problems:
item = item.split()
number1 = item.strip(" ")
number2 = item.strip(" ")
operand = item.strip(" ")
try:
int(number1)
int(number2)
except:
return"Error: Operator must be '+' or '-'.'"
break
if len(number1) > 4 or len(number2) > 4:
return"Error: Numbers cannot be more than four digits."
break
if operand == "*" or operand == "/":
return"Error: Operator must be '+' or '-'."
break
if  operand == '+':
sumx = str(int(number1) + int(number2))
elif operand == "-":
sumx = str(int(number1) - int(number2))
spaces = max(len(number1), len(number2))+2

line1 += str(number1).rjust(spaces)
line2 += str(operand + number2.rjust(spaces-1))
line3 += ('-' * spaces)
line4 += str(sumx).rjust(spaces)

if item != problems[-1]:
line1 += "    "
line2 += "    "
line3 += "    "
line4 += "    "

if args:
arranged_problems = line1 + "\n" + line2 + "\n" + line3 + "\n" + line4
else:
arranged_problems = line1 + "\n" + line2 + "\n" + line3
print(arranged_problems)

return arranged_problems
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4620.0 Safari/537.36`

Challenge: Scientific Computing with Python Projects - Arithmetic Formatter

It is hard to guess without the test output. Can you provide the diffs?

@darylhurst86

In the first test case, the expected return value is:

``````'  3801      123\n-    2    +  49\n------    -----'
``````

``````'  3801      123    \n-    2    +  49    \n------    -----    '
You have an extra 4 spaces between `123` and `\n` and between `49` and `\n------`. Also, you have extra 4 spaces after the final `-----`.