Scientific Computing with Python Projects - Arithmetic Formatter

Tell us what’s happening:
i cant make it work error:

=================================== FAILURES ===================================
_______________ 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 None == '    3      988\n+ 855    +  40\n-----    -----\n  858     1028'
E         +None
E         -'    3      988\n+ 855    +  40\n-----    -----\n  858     1028'

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 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
=========================== short test summary info ============================
FAILED test_module.py::test_template[test_two_problems_with_solutions] - Asse...
FAILED test_module.py::test_template[test_five_problems_with_solutions] - Ass...
========================= 2 failed, 8 passed in 0.21s ==========================
          

Your code so far

import re
def arithmetic_arranger(problems,check=False):
  
    if len(problems)>5:
     return "Error: Too many problems."
  
    
    lineas=""
    
    suma1=""
    pri=""
    seg=""
    resultado=""
    
    for val in (problems):
      if (re.search("[^\s0-9.+-]", val)):
        if (re.search("[/]",val) or re.search("[*]",val)): 
         return "Error: Operator must be '+' or '-'."
        return "Error: Numbers must only contain digits."
      valor1=val.split(" ")[0]
      operator=val.split(" ")[1]
      valor2=val.split(" ")[2]
    
     
       
      
      if len(valor1)>4 or len(valor2)>4:
       return "Error: Numbers cannot be more than four digits."
      sum=""
      if operator=="+":
        sum=str(int(valor1)+int(valor2))
      elif operator=="-":
        sum=str(int(valor1)-int(valor2))
       
      width=max(len(valor1), len(valor2)) +2
      #suma=str(splited[0])-int(splited[2])
      #total=signo[operator](int(valor1),int(valor2))
      #width=max(len(valor1),len(valor2))+2
      linea=""
      arriba=str(valor1).rjust(width)
      abajo=operator+str(valor2).rjust(width-1)
      result=str(sum).rjust(width)
      
    
      
      for r in range(width):
        linea +="-"
      if val!=problems[-1]:
        pri+= arriba + '    ' 
        seg+= abajo + '    '
        lineas+= linea + '    '
        suma1+= result + '    '
      else:
        pri+= arriba
        seg+= abajo 
        lineas+= linea
        suma1+= result
    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:
https://www.freecodecamp.org/learn/scientific-computing-with-python/scientific-computing-with-python-projects/arithmetic-formatter

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 (').

The errors are saying that your output is incorrect for the case when the parameter check is true.

Have you tried testing your code with check set to true to confirm the output visually?

Please share a replit link as well (place the link in angled brackets when you copy it here)