Arithmetic Formatter - Help with Replit

Hey guys, I posted my code on replit for testing and this is the following output:

 python main.py
  32      3801      45      123     
+698     -   2     +43     + 49     
____     _____     ___     ____     
 730      3799      88      172     
======================================= test session starts =======================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /home/runner/boilerplate-arithmetic-formatter-2/venv/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/boilerplate-arithmetic-formatter-2
collected 0 items                                                                                 

====================================== no tests ran in 0.01s ======================================
 

Ps: The lines seem not aligned but in Replit it looks fine

What is wrong with it? Is it ok?

can you post a link to the replit? (put the link inside angled brackets otherwise it won’t show up)

1 Like

I added a space between the operator and longest operand and now a lot mistakes appeared. Here is my replit code:

{boilerplate-arithmetic-formatter - Python Repl - Replit}

Okay. Let us know if you need further help.

1 Like

This is the output that shows on my VsCode:

  32ssss     1ssss  9999ssss  523ssss
+  8ssss- 3801ssss+ 9999ssss-  49ssss
____ssss______ssss______ssss_____ssss
  40ssss  3800ssss 19998ssss  474ssss
PS C:\Users\Christopher\Desktop\Github local repositories> 

When you run your code it should show you the errors. Do you need help understanding these? (If yes, you should post the output in full)

1 Like

I was able to succesfully delete the last ’ ssss’ spaces at the end of each line. But there are still some error messages on Replit. I’ll admit, it is a bit hard to understand what the compiler is trying to tell me, I’ll paste the messages bellow:

  32         2      9999      523
+  8    - 3801    + 9999    -  49
____    ______    ______    _____
  40      3799     19998      474
   32      3801      45      123
+ 698    -    2    + 43    +  49
_____    ______    ____    _____
  730      3799      88      172
========================== test session starts ==========================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /home/runner/boilerplate-arithmetic-formatter/venv/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/boilerplate-arithmetic-formatter
collected 10 items                                                      

test_module.py::test_template[test_two_problems_arrangement1] FAILED [ 10%]
test_module.py::test_template[test_two_problems_arrangement2] FAILED [ 20%]
test_module.py::test_template[test_four_problems_arrangement] FAILED [ 30%]
test_module.py::test_template[test_five_problems_arrangement] FAILED [ 40%]
test_module.py::test_template[test_too_many_problems] FAILED      [ 50%]
test_module.py::test_template[test_incorrect_operator] FAILED     [ 60%]
test_module.py::test_template[test_too_many_digits] FAILED        [ 70%]
test_module.py::test_template[test_only_digits] FAILED            [ 80%]
test_module.py::test_template[test_two_problems_with_solutions] FAILED [ 90%]
test_module.py::test_template[test_five_problems_with_solutions] FAILED [100%]

=============================== FAILURES ================================
_____________ test_template[test_two_problems_arrangement1] _____________

arguments = [['3801 - 2', '123 + 49']]
expected_output = '  3801      123\n-    2    +  49\n------    -----'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]'

    @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 different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]
E       assert '  3801      123\n-    2    +  49\n______    _____\n  3799      172' == '  3801      123\n-    2    +  49\n------    -----'
E             3801      123
E           -    2    +  49
E         - ------    -----
E         + ______    _____
E         +   3799      172

test_module.py:77: AssertionError
_____________ test_template[test_two_problems_arrangement2] _____________

arguments = [['1 + 2', '1 - 9380']]
expected_output = '  1         1\n+ 2    - 9380\n---    ------'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["1 + 2", "1 - 9380"]'

    @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 different output when calling "arithmetic_arranger()" with ["1 + 2", "1 - 9380"]
E       assert '  1         1\n+ 2    - 9380\n___    ______\n  3      9379' == '  1         1\n+ 2    - 9380\n---    ------'
E             1         1
E           + 2    - 9380
E         - ---    ------
E         + ___    ______
E         +   3      9379

test_module.py:77: AssertionError
_____________ test_template[test_four_problems_arrangement] _____________

arguments = [['3 + 855', '3801 - 2', '45 + 43', '123 + 49']]
expected_output = '    3      3801      45      123\n+ 855    -    2    + 43    +  49\n-----    ------    ----    -----'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]'

    @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 different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]
E       assert ('    3      3801      45      123\n'\n '+ 855    -    2    + 43    +  49\n'\n '_____    ______    ____    _____\n'\n '  858      3799      88      172') == ('    3      3801      45      123\n'\n '+ 855    -    2    + 43    +  49\n'\n '-----    ------    ----    -----')
E               3      3801      45      123
E           + 855    -    2    + 43    +  49
E         - -----    ------    ----    -----
E         + _____    ______    ____    _____
E         +   858      3799      88      172

test_module.py:77: AssertionError
_____________ test_template[test_five_problems_arrangement] _____________

arguments = [['11 + 4', '3801 - 2999', '1 + 2', '123 + 49', '1 - 9380']]
expected_output = '  11      3801      1      123         1\n+  4    - 2999    + 2    +  49    - 9380\n----    ------    ---    -----    ------'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]'

    @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 different output when calling "arithmetic_arranger()" with ["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]
E       assert ('  11      3801      1      123         1\n'\n '+  4    - 2999    + 2    +  49    - 9380\n'\n '____    ______    ___    _____    ______\n'\n '  15      802      3      172      9379') == ('  11      3801      1      123         1\n'\n '+  4    - 2999    + 2    +  49    - 9380\n'\n '----    ------    ---    -----    ------')
E             11      3801      1      123         1
E           +  4    - 2999    + 2    +  49    - 9380
E         - ----    ------    ---    -----    ------
E         + ____    ______    ___    _____    ______
E         +   15      802      3      172      9379

test_module.py:77: AssertionError
_________________ 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 'Error: Too many problems' == 'Error: Too many problems.'
E         - Error: Too many problems.
E         ?                         -
E         + Error: Too many problems

test_module.py:77: AssertionError
________________ test_template[test_incorrect_operator] _________________

arguments = [['3 / 855', '3801 - 2', '45 + 43', '123 + 49']]
expected_output = "Error: Operator must be '+' or '-'."
fail_message = 'Expected calling "arithmetic_arranger()" with a problem that uses the "/" operator to return "Error: Operator must be \'+\' or \'-\'."'

    @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 a problem that uses the "/" operator to return "Error: Operator must be '+' or '-'."
E       assert 'Error: Operator must either be + or -' == "Error: Operator must be '+' or '-'."
E         - Error: Operator must be '+' or '-'.
E         ?                         - -    - --
E         + Error: Operator must either be + or -
E         ?                      +++++++

test_module.py:77: AssertionError
__________________ test_template[test_too_many_digits] __________________

arguments = [['24 + 85215', '3801 - 2', '45 + 43', '123 + 49']]
expected_output = 'Error: Numbers cannot be more than four digits.'
fail_message = 'Expected calling "arithmetic_arranger()" with a problem that has a number over 4 digits long to return "Error: Numbers cannot be more than four digits."'

    @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 a problem that has a number over 4 digits long to return "Error: Numbers cannot be more than four digits."
E       assert 'Numbers cannot be more than four digits' == 'Error: Numbers cannot be more than four digits.'
E         - Error: Numbers cannot be more than four digits.
E         ? -------                                       -
E         + Numbers cannot be more than four digits

test_module.py:77: AssertionError
____________________ test_template[test_only_digits] ____________________

arguments = [['98 + 3g5', '3801 - 2', '45 + 43', '123 + 49']]
expected_output = 'Error: Numbers must only contain digits.'
fail_message = 'Expected calling "arithmetic_arranger()" with a problem that contains a letter character in the number to return "Error: Numbers must only contain digits."'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
>       actual = arithmetic_arranger(*arguments)

test_module.py:76: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = ['98 + 3g5', '3801 - 2', '45 + 43', '123 + 49']

    def arithmetic_arranger(self):
    
    #---Checks if the length of the list is larger than 5.
        if len(self)>5:
            return 'Error: Too many problems'
        row_one = [ ]
        new_line= ['\n']
        row_two = [ ]
        row_three = [ ]
        row_four = [ ]
        rows_combined =[]
    
     #--Beginning of the For Loop
        for each_index in self:
            each_index = each_index.replace(' ','')
     #------If/else block, the operator will have different values depending on which operator is present in the string.
            if '+' in each_index:
                operator = '+'
            elif '-' in each_index:
                operator = '-'
            else:
                return 'Error: Operator must either be + or -'
    #-------Assigning the variables to compose the operands and result.
            n = each_index.index(operator)
            operand_one = each_index[0:n]
            operand_two = each_index[n+1:]
            combinedoperands = operand_one+operand_two
            num1 = int(operand_one)
>           num2 = int(operand_two)
E           ValueError: invalid literal for int() with base 10: '3g5'

arithmetic_arranger.py:29: ValueError
____________ test_template[test_two_problems_with_solutions] ____________

arguments = [['3 + 855', '988 + 40'], True]
expected_output = '    3      988\n+ 855    +  40\n-----    -----\n  858     1028'
fail_message = 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with ["3 + 855", "988 + 40"] 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)
E       TypeError: arithmetic_arranger() takes 1 positional argument but 2 were given

test_module.py:76: TypeError
___________ 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)
E       TypeError: arithmetic_arranger() takes 1 positional argument but 2 were given

test_module.py:76: TypeError
======================== short test summary info ========================
FAILED test_module.py::test_template[test_two_problems_arrangement1]
FAILED test_module.py::test_template[test_two_problems_arrangement2]
FAILED test_module.py::test_template[test_four_problems_arrangement]
FAILED test_module.py::test_template[test_five_problems_arrangement]
FAILED test_module.py::test_template[test_too_many_problems] - Asserti...
FAILED test_module.py::test_template[test_incorrect_operator] - Assert...
FAILED test_module.py::test_template[test_too_many_digits] - Assertion...
FAILED test_module.py::test_template[test_only_digits] - ValueError: i...
FAILED test_module.py::test_template[test_two_problems_with_solutions]
FAILED test_module.py::test_template[test_five_problems_with_solutions]
========================== 10 failed in 0.31s ===========================

what character are you using to make the dashes? It should be the minus symbol like -

1 Like

I was using underscore ‘_’ for the dashes, I changed and there are still some errors appearing.

I am looking for tutorials on how to understand the error messages in replit.

Yeah there are more errors in the list. You just have to read one error at a time. Paying attention to what is “expected”. here is the bottom most one for eg:

If you read from the top, the test case is called test_five_problems_with_solutions

So that tells you something there then,
you can see a line with the arguments they used.
They passed in an array of 5 calculations and true.
Then they show the expected output.

So you can stop there if you want and just test your code and compare yourself or you can continue to read.
And the next line says what they were expecting (the 5 problems with their solutions correctly displayed)
And after that it shows that there is a TypeError so perhaps your function is not handling the optional parameter?

That’s basically how you read that.

1 Like

Interesting… I didn’t use the optional parameter because I thought it was optional for the completion of the challenge

It turns out that a lot the of the Error messages on replit were because I didn’t put the literal error message (with periods and everything). I changed the text from my code and now I have eight sucessful tests out of ten. I just need to figure out the other two.

1 Like

I am happy to inform that my code has passed all tests on replit.

Thank you all for your help

I am thrilled!

========================== test session starts ===========================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /home/runner/boilerplate-arithmetic-formatter/venv/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/boilerplate-arithmetic-formatter
collected 10 items                                                       

test_module.py::test_template[test_two_problems_arrangement1] PASSED [ 10%]
test_module.py::test_template[test_two_problems_arrangement2] PASSED [ 20%]
test_module.py::test_template[test_four_problems_arrangement] PASSED [ 30%]
test_module.py::test_template[test_five_problems_arrangement] PASSED [ 40%]
test_module.py::test_template[test_too_many_problems] PASSED       [ 50%]
test_module.py::test_template[test_incorrect_operator] PASSED      [ 60%]
test_module.py::test_template[test_too_many_digits] PASSED         [ 70%]
test_module.py::test_template[test_only_digits] PASSED             [ 80%]
test_module.py::test_template[test_two_problems_with_solutions] PASSED [ 90%]
test_module.py::test_template[test_five_problems_with_solutions] PASSED [100%]

=========================== 10 passed in 0.14s ===========================
 
1 Like

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