# Help with Arithmetic arranger

Hi! Can someone help with this project? I really prefer to work on my laptop in VSC. And I tested all the exemples from the test._module.py and it works fine. But when I try to run my program into replit it seems that everything fails. Can somebody help me ?
My code:

``````def arithmetic_arranger(problems, include_result = False):
#  If there are too many problems supplied (>5) to the function we have an error
if len(problems) > 5:
return print("Error: Too many problems")

operators = ["+", "-"]
# List for each line to print
line1 = []
line2 = []
line3 = []
line4 = []

for value in problems:
operation = value.split(" ")

# Error for non admissible operators
if operation not in operators:
return(print("Error: Operator must be '+' or '-'."))

# Assign operand values
operand_1 = operation
operand_2 = operation

# Operands must only contains digits. Otherwise operation non admited
if operand_1.isdigit() == False or operand_2.isdigit() == False :
return (print("Error: Numbers must only contain digits"))

# Max of four digits for each operand
if len(operand_1) > 4 or len(operand_2) > 4:
return print("Error: Numbers cannot be more than four digits.")

# Max spaces to fill in the final print. We will find the longest operand and we add
# the operator's space and the space btw the operator and the second element
max_spaces_to_fill = max(len(x) for x in operation)
dash = "-"
space = " "

# Append each first operand and we add 4 spaces btw each operation
line1.append(operand_1.rjust(max_spaces_to_fill+2)+ space*4)
# Append the operator, space and second operand
line2.append(operation + space + operand_2.rjust(max_spaces_to_fill)+space*4)
# Append dash line
line3.append(dash * (max_spaces_to_fill+2)+space*4)
# Append the result line in case argument include_result = True
result = (str(eval(value)))
line4.append(result.rjust(max_spaces_to_fill+2)+space*4)

# Transform each list in string
line1= ''.join(map(str, line1))
line2 = ''.join(map(str, line2))
line3 = ''.join(map(str, line3))
line4 = ''.join(map(str, line4))
# If second argument true, include results
if include_result == True:
arranged_problems = line1 + "\n" + line2 + "\n"+ line3+ "\n"+ line4
# If second argument false, only print operation
if include_result == False:
arranged_problems = line1 + "\n" + line2 + "\n"+ line3
print(arranged_problems)
return arranged_problems

arithmetic_arranger( ["3801 - 2", "123 + 49"], True)
``````

Thanks!!!

I’m not sure what this means, but you should be able to run the `main.py` file with your python interpreter and execute all the tests on your local computer and then use the error messages to debug.

The easiest problems are these:

which generate messages like

``````_____________________ test_template[test_too_many_problems] ______________________

arguments = [['44 + 815', '909 - 2', '45 + 43', '123 + 49', '888 + 40', '653 + 87']]
expected_output = 'Error: Too many problems.'
fail_message = 'Expected calling "arithmetic_arranger()" with more than five problems to return "Error: Too many problems."'

@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 calling "arithmetic_arranger()" with more than five problems to return "Error: Too many problems."
E       assert None == 'Error: Too many problems.'

test_module.py:181: AssertionError
``````

The spec says to return the error message, not return the value from printing it. That’s what the last line of the error is trying to tell you. The tests are picky about the string you return.

The rest of the problems are from formatting like here:

``````>       assert actual == expected_output, fail_message
E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]
E       assert '  11      38...   ------    ' == '  11      38...---    ------'
E         -   11      3801      1      123         1
E         +   11      3801      1      123         1
E         ?                                         ++++
E         - +  4    - 2999    + 2    +  49    - 9380
E         + +  4    - 2999    + 2    +  49    - 9380
E         ?                                         ++++
E         - ----    ------    ---    -----    ------...
E
E         ...Full output truncated (3 lines hidden), use '-vv' to show
``````

Those `+` signs on the end of each line are indicating differences in your output and the expected output. In this case, it’s four extra spaces on the end of the line.

1 Like

Thank you, Jeremy! This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.