# Don't understand the fail msg

It seems like all the fails are because of a display problem I’m just not sure what it is.

``````import re

def arithmetic_arranger(problems, solve = False):

top = ""
bottom = ""
line = ""
#Errors
for problem in problems:
if(re.search("[*]" or "[/]" , problem)):
return "Error: equations must be addition or subtraction."

first_num = problem.split(" ")[0]
operator = problem.split(" ")[1]
second_num = problem.split(" ")[2]

if(len(first_num) >= 5) or len(second_num) >= 5:
return "Error: numbers cannot be more than four digits."
if(re.search("[^sa-zA-Z0-9.+-]" , first_num or second_num)):
return "Error: Numbers must only contain digits."

sum = ""
if(operator == "+"):
sum = str(int(first_num) + int(second_num))
elif(operator == "-"):
sum = str(int(first_num) - int(second_num))

length = max(len(first_num), len(second_num))
top = str(first_num).rjust(length)
bottom = operator + str(second_num)
line = ""
for x in range(length):
line +="-"

if problem != problems[-1]:
top += top + " "
bottom += bottom + " "
line += line + " "
else :
top += top
bottom += bottom
line += line

if solve:
display = top + "/n" + bottom + "/n" + line + "/n" + answer
else:
display = top + "/n" + bottom + "/n" + line
print(display)

One of the errors:

_______________ test_template[test_five_problems_with_solutions] _______________

arguments = [['32 - 698', '1 - 3801', '45 + 43', '123 + 49', '988 + 40'], True]
expected_output = '   32         1      45      123      988\n- 698    - 3801    + 43    +  49    +  40\n-----    ------    ----    -----    -----\n -666     -3800      88      172     1028'
fail_message = 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with five arithmetic problems and a second argument of `True`.'

@pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
def test_template(arguments, expected_output, fail_message):
actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with five arithmetic problems and a second argument of `True`.
E       assert None == ('   32         1      45      123      988\n'\n '- 698    - 3801    + 43    +  49    +  40\n'\n '-----    ------    ----    -----    -----\n'\n ' -666     -3800      88      172     1028')
E         +None
E         -'   32         1      45      123      988\n- 698    - 3801    + 43    +  49    +  40\n-----    ------    ----    -----    -----\n -666     -3800      88      172     1028'

test_module.py:77: AssertionError``````

Please don’t spam multiple posts if a post gets caught in the review filter. Thanks.

I was trying to format it so it wouldn’t get caught in the automatic filter… I didn’t think it would upset anyone sorry.

yes but this is the only post with my code in it

Since you deleted the only post that wasn’t unlisted, I’ll re-list this post.

oh i’m sorry it didn’t show up like it did in this post.

The link is better because it lets us see all of the test output.

It looks like you are printing the results instead of returning them.

1 Like

Welp, the error is straightforward: the `actual` outpu is `None` and the `expected_output` is a string

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.