# Scientific Computing with Python Projects - Arithmetic Formatter

Tell us what’s happening:
Describe your issue in detail here.
Code outputs the format correctly without solution=true. Unfortunately for whatever reason it’s not accepted.
https://replit.com/@J1Universe/boilerplate-arithmetic-formatter#arithmetic_arranger.py
import re
def arithmetic_arranger(problems, sovle=False):
number1=0
number2=0
operator=“”
sum=0
top=“”
med=“”
bottom=“”
lines=“”
count=0

string =
if len(problems) >5:
return ‘Error: Too many problems.’
for problem in problems:
if re.search(‘[a-zA-z]’,problem):
return “Error: Numbers must only contain digits.”
else:
if (‘'in problem or "/“in problem):
return “Error: Operator must be ‘+’ or ‘-’.”
number1 = problem.split(” “)[0]
operator = problem.split(” “)[1]
number2 = problem.split(” ")[2]
if len(number1)>4 or len(number2)>4:
return ‘Error: Numbers cannot be more than four digits.’
else:
if count < len(problems):
line=str(findLine(number1,number2))
lines+= findLine(number1,number2) + ’ ’
top+= ((len(line) - len(number1))
’ ‘)+ str(number1) + ’ ’
med+=(operator+ (len(line) -1 - len(number2))* ’ ‘)+str(number2)+ ’ ’
string = top +’\n’+ med +’\n’+ lines
count+=1
elif count == len(problems):
line=str(findLine(number1,number2))
lines+= findLine(number1,number2)
top+= ((len(line) - len(number1))* ’ ‘)+ str(number1)
med+=(operator+ (len(line) -1 - len(number2))* ’ ‘)+str(number2)
string = top +’\n’+ med +‘\n’+ lines
print(string)

return string

def findLine(number1,number2):
line=“—”
i=2
if len(number1)>= len(number2):
while i <= len(number1):
line+=‘-’
i+=1
else:
while i <= len(number2):
line+=‘-’
i+=1
return line

Chrome
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

can you post a link to your replit project (place the link in angled brackets so it displays on the forum)

``````mport re
def arithmetic_arranger(problems, sovle=False):
number1=0
number2=0
operator=""
sum=0
top=""
med=""
bottom=""
lines=""
count=0

string = []
if len(problems) >5:
return 'Error: Too many problems.'
for problem in problems:
if re.search('[a-zA-z]',problem):
return "Error: Numbers must only contain digits."
else:
if ('*'in problem or "/"in problem):
return "Error: Operator must be '+' or '-'."
number1 = problem.split(" ")[0]
operator = problem.split(" ")[1]
number2 = problem.split(" ")[2]
if len(number1)>4 or len(number2)>4:
return 'Error: Numbers cannot be more than four digits.'
else:
if count < len(problems):
line=str(findLine(number1,number2))
lines+= findLine(number1,number2) + '    '
top+= ((len(line)  - len(number1))* ' ')+ str(number1) + '    '
med+=(operator+ (len(line) -1  - len(number2))* ' ')+str(number2)+ '    '
string = top +'\n'+ med +'\n'+ lines
count+=1
elif count == len(problems):
line=str(findLine(number1,number2))
lines+= findLine(number1,number2)
top+= ((len(line)  - len(number1))* ' ')+ str(number1)
med+=(operator+ (len(line) -1  - len(number2))* ' ')+str(number2)
string = top +'\n'+ med +'\n'+ lines
print(string)
return string

def findLine(number1,number2):
line="---"
i=2
if len(number1)>= len(number2):
while i <= len(number1):
line+='-'
i+=1
else:
while i <= len(number2):
line+='-'
i+=1
return line

``````
``````   32      3801      45      123
+ 698    -    2    + 43    +  49
-----    ------    ----    -----
====================================== test session starts =======================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /home/runner/0G2j8IuTmeF/venv/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/0G2j8IuTmeF
collected 10 items

test_module.py::test_template[test_two_problems_arrangement1] <- ../boilerplate-arithmetic-formatter/test_module.py FAILED [ 10%]
test_module.py::test_template[test_two_problems_arrangement2] <- ../boilerplate-arithmetic-formatter/test_module.py FAILED [ 20%]
test_module.py::test_template[test_four_problems_arrangement] <- ../boilerplate-arithmetic-formatter/test_module.py FAILED [ 30%]
test_module.py::test_template[test_five_problems_arrangement] <- ../boilerplate-arithmetic-formatter/test_module.py FAILED [ 40%]
test_module.py::test_template[test_too_many_problems] <- ../boilerplate-arithmetic-formatter/test_module.py PASSED [ 50%]
test_module.py::test_template[test_incorrect_operator] <- ../boilerplate-arithmetic-formatter/test_module.py PASSED [ 60%]
test_module.py::test_template[test_too_many_digits] <- ../boilerplate-arithmetic-formatter/test_module.py PASSED [ 70%]
test_module.py::test_template[test_only_digits] <- ../boilerplate-arithmetic-formatter/test_module.py PASSED [ 80%]
test_module.py::test_template[test_two_problems_with_solutions] <- ../boilerplate-arithmetic-formatter/test_module.py FAILED [ 90%]
test_module.py::test_template[test_five_problems_with_solutions] <- ../boilerplate-arithmetic-formatter/test_module.py 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"]'

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

/home/runner/boilerplate-arithmetic-formatter/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"]'

>   ???
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     ?              ++++

/home/runner/boilerplate-arithmetic-formatter/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"]'

>   ???
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     ?                                 ++++

/home/runner/boilerplate-arithmetic-formatter/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"]'

>   ???
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     ?                                         ++++

/home/runner/boilerplate-arithmetic-formatter/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`.'

>   ???
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-----    -----    ' == '    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     ?               ^^^^
E     -   858     1028

/home/runner/boilerplate-arithmetic-formatter/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`.'

>   ???
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 '-----    ------    ----    -----    -----    ') == ('   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     ?                                          ^^^^
E     -  -666     -3800      88      172     1028

/home/runner/boilerplate-arithmetic-formatter/test_module.py:77: AssertionError
==================================== short test summary info =====================================
FAILED test_module.py::test_template[test_two_problems_arrangement1] - AssertionError: Expected...
FAILED test_module.py::test_template[test_two_problems_arrangement2] - AssertionError: Expected...
FAILED test_module.py::test_template[test_four_problems_arrangement] - AssertionError: Expected...
FAILED test_module.py::test_template[test_five_problems_arrangement] - AssertionError: Expected...
FAILED test_module.py::test_template[test_two_problems_with_solutions] - AssertionError: Expect...
FAILED test_module.py::test_template[test_five_problems_with_solutions] - AssertionError: Expec...
================================== 6 failed, 4 passed in 0.20s ===================================
``````

you have 4 extra space-like characters to the right of each line that is causing this error message(s). You can see that in the ++++ which indicates the location of the unexpected space-like characters.