Scientific Computing with Python Projects - Arithmetic Formatter

hi, i can make this program works idk whats wrong, i get 4 of 6 passed

E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["1 + 2", "1 - 9380"]
E       assert '  1         1    \n+ 2    - 9380    \n---    ------    ' == '  1         1\n+ 2    - 9380\n---    ------'
E         -   1         1
E         +   1         1    
E         ?              ++++
E         - + 2    - 9380
E         + + 2    - 9380    
E         ?              ++++
E         - ---    ------
E         + ---    ------    
E         ?              ++++

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 '-----    ------    ----    -----    ') == ('    3      3801      45      123\n'\n '+ 855    -    2    + 43    +  49\n'\n '-----    ------    ----    -----')
E         -     3      3801      45      123
E         +     3      3801      45      123    
E         ?                                 ++++
E         - + 855    -    2    + 43    +  49
E         + + 855    -    2    + 43    +  49    
E         ?                                 ++++
E         - -----    ------    ----    -----
E         + -----    ------    ----    -----    
E         ?                                 ++++

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 '----    ------    ---    -----    ------    ') == ('  11      3801      1      123         1\n'\n '+  4    - 2999    + 2    +  49    - 9380\n'\n '----    ------    ---    -----    ------')
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         ?                                         ++++

test_module.py:77: AssertionError
_ 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)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with ["3 + 855", "988 + 40"] and a second argument of `True`.
E       assert '    3      988    \n+ 855    +  40    \n-----    -----    \n  858     1028    ' == '    3      988\n+ 855    +  40\n-----    -----\n  858     1028'
E         -     3      988
E         +     3      988    
E         ?               ++++
E         - + 855    +  40
E         + + 855    +  40    
E         ?               ++++
E         - -----    -----
E         + -----    -----    
E         ?               ++++
E         -   858     1028
E         +   858     1028    
E         ?               ++++

test_module.py:77: AssertionError
_ 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 ('   32         1      45      123      988    \n'\n '- 698    - 3801    + 43    +  49    +  40    \n'\n '-----    ------    ----    -----    -----    \n'\n ' -666     -3800      88      172     1028    ') == ('   32         1      45      123      988\n'\n '- 698    - 3801    + 43    +  49    +  40\n'\n '-----    ------    ----    -----    -----\n'\n ' -666     -3800      88      172     1028')
E         -    32         1      45      123      988
E         +    32         1      45      123      988    
E         ?                                          ++++
E         - - 698    - 3801    + 43    +  49    +  40
E         + - 698    - 3801    + 43    +  49    +  40    
E         ?                                          ++++
E         - -----    ------    ----    -----    -----
E         + -----    ------    ----    -----    -----    
E         ?                                          ++++
E         -  -666     -3800      88      172     1028
E         +  -666     -3800      88      172     1028    
E         ?                                          ++++

test_module.py:77: AssertionError
============ 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_two_problems_with_solutions]
FAILED test_module.py::test_template[test_five_problems_with_solutions]
========== 6 failed, 4 passed in 0.28s

i search for a ton of help but i cant make it work pls help.
thats my code:


def arithmetic_arranger(problems,check=False):
    if len(problems)>5:
     return "Error: Too many problems."
  
    pri=""
    seg=""
    lineas=""
    suma1=""

          

    for key,val in enumerate(problems):
        
      splited=val.split(" ")
      

      if splited[1]=="/" or splited[1]=="*":
       return "Error: Operator must be '+' or '-'."
      if len(splited[0])>4 or len(splited[2])>4:
       return "Error: Numbers cannot be more than four digits."
      try:
         splited[0]=int(splited[0])
         splited[2]=int(splited[2])
      except:
       return "Error: Numbers must only contain digits."
      if splited[1]=="+":
          suma=str(int(splited[0])+int(splited[2]))
      elif splited[1]=="-":
          suma=str(int(splited[0])-int(splited[2]))
        
      width=max(len(str(splited[0])),len(str(splited[2]))) +2
      arriba=str(splited[0]).rjust(width)
      abajo=splited[1]+str(splited[2]).rjust(width-1)
      linea=""
      resto=str(suma).rjust(width)
      for r in range (width):
          linea +="-"
      if splited!=problems[-1]:
          pri+= arriba + "    "
          seg+= abajo + "    "
          lineas+= linea+ "    "
          suma1+= resto+ "    "
      else:
          pri+= arriba
          seg+= abajo 
          lineas+= linea
          suma1+= resto
    if check:
     resultado= pri + "\n"+seg+ "\n"+lineas+ "\n"+suma1
    else:
     resultado =pri+"\n"+seg+"\n"+lineas
    
    return resultado

Your browser information:

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

Challenge: Scientific Computing with Python Projects - Arithmetic Formatter

Link to the challenge:

Please post the full error message so we can see what’s wrong with your code. Thanks

i cant put all the errors

You added enough for me to be able to see what’s happening. Thanks

This says that you are adding 4 extra spaces at the end of every row

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').