# Scientific Computing with Python Projects - Arithmetic Formatter

**URL:** <https://forum.freecodecamp.org/t/scientific-computing-with-python-projects-arithmetic-formatter/590992>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [February 9, 2023, 5:57am UTC](https://forum.freecodecamp.org/t/scientific-computing-with-python-projects-arithmetic-formatter/590992 "2023-02-09T05:57:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bubaloox](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@Bubaloox](https://forum.freecodecamp.org/u/Bubaloox)\
**Post date:** [February 9, 2023, 5:57am UTC](https://forum.freecodecamp.org/t/scientific-computing-with-python-projects-arithmetic-formatter/590992/1 "2023-02-09T05:57:12Z")

</div>

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

```auto
=================================== 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**

```auto
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](https://www.freecodecamp.org/learn/scientific-computing-with-python/scientific-computing-with-python-projects/arithmetic-formatter)

---

<div class="post-metadata">

**Author:** ![hbar1st](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbar1st/32/372649_2.png) [@hbar1st](https://forum.freecodecamp.org/u/hbar1st)\
**Post date:** [February 9, 2023, 9:26am UTC](https://forum.freecodecamp.org/t/scientific-computing-with-python-projects-arithmetic-formatter/590992/2 "2023-02-09T09:26:02Z")

</div>

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.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (').

---

<div class="post-metadata">

**Author:** ![hbar1st](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbar1st/32/372649_2.png) [@hbar1st](https://forum.freecodecamp.org/u/hbar1st)\
**Post date:** [February 9, 2023, 9:28am UTC](https://forum.freecodecamp.org/t/scientific-computing-with-python-projects-arithmetic-formatter/590992/3 "2023-02-09T09:28:09Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [August 10, 2023, 9:29pm UTC](https://forum.freecodecamp.org/t/scientific-computing-with-python-projects-arithmetic-formatter/590992/4 "2023-08-10T21:29:06Z")

</div>

Closed on August 10, 2023, 9:29pm UTC

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