Arithmetic Formatter Issues

I’ve written the code using VsCode and everything works as per criteria on VsCode but not when using replit.

``````def arithmetic_arranger(val, para2=False):
listlength= len(val)
row1=""
row2=""
row3=""
row4=""
space=""
space4=""
len4=0
spaceans=""
probnum=0
#---------------------------TESTING IF LIST IS GREATER THAN 5--------------------------------

if (listlength>5):
return("Error: Too many problems.")
#----------------------------SPLITTING STRINGS FROM THE LIST OF STRINGS -------------------------
print(" ",end="")
for i in val:
probnum=probnum+1
string= i.split()
val1=string[0]
val2=string[1]
val3=string[2]
#-------------------------TEST IF CONTAINS NUMBERS ONLY AND NOT GREATER THAN 4 DIGITS-------------------------------

for z in val:
try:
float(val1)
except ValueError:
return("Error: Numbers must only contain digits.")

if(len(val1)>4 or len(val3)>4):
return("Error: Numbers cannot be more than four digits.")

#-------------------------CASTING STRING TO INTEGER---------------------
int1= int(val1)
int3= int(val3)

if (val2=='+'):
ans= int1+int3
elif (val2=="-"):
ans= int1-int3
elif (val2=="*" or val2=="/"):
return("Error: Operator must be '+' or '-'.")
ans= str(ans)
#-----------------------------OUTSTRING MAKING-----------------------
if (len(val1)>len(val3)):
lens= len(val1)-len(val3)
space=" "
space4=""
for j in range(lens):
space=space+" "

if (probnum==listlength):
row1=row1 +" "+val1
else:
row1=row1 +" "+val1+"     "

if (probnum==listlength):
row2=row2+ val2+space+val3
else:
row2=row2+ val2+space+val3+"    "

for k in range(len(val2+space+val3)):
row3= row3+"-"
space4= space4+"-"

if (probnum==listlength):
row3= row3
else:
row3= row3+"    "

len4=(len(space4)-len(ans))
for m in range (len4):
spaceans=spaceans+" "

if (probnum==listlength):
row4=row4+spaceans+ans
else:
row4=row4+spaceans+ans+"    "
spaceans=""

if (len(val3)>len(val1)):
lens= len(val3)-len(val1)
space=" "
space4=""
for l in range(lens):
space=space+" "
if (probnum==listlength):
row1=row1 +space+val1
else:
row1=row1 +space+val1+"     "

if (probnum==listlength):
row2=row2+ val2+" "+val3
else:
row2=row2+ val2+" "+val3 +"    "

for o in range(len(val2+" "+val3)):
row3= row3+"-"
space4= space4+"-"

if (probnum==listlength):
row3= row3
else:
row3= row3+"    "

len4=(len(space4)-len(ans))
for p in range (len4):
spaceans=spaceans+" "

if (probnum==listlength):
row4=row4+spaceans+ans
else:
row4=row4+spaceans+ans+"    "
spaceans=""

if (len(val3)==len(val1)):
space4=""

if (probnum==listlength):
row1=row1 +" "+val1
else:
row1=row1 +" "+val1+"     "

if (probnum==listlength):
row2=row2+ val2+" "+val3
else:
row2=row2+ val2+" "+val3+"    "

for x in range (len(val1)+2):
row3= row3+"-"
space4= space4+"-"

if (probnum==listlength):
row3= row3
else:
row3= row3+"    "

len4=(len(space4)-len(ans))
for p in range (len4):
spaceans=spaceans+" "
if (probnum==listlength):
row4=row4+spaceans+ans
else:
row4=row4+spaceans+ans+"    "

spaceans=""

#----------------------RETURNING CONCATENATED STRING-------------------------
if (para2==True):
return(row1+"\n"+row2+"\n"+row3+"\n"+row4)
else:
return(row1+"\n"+row2+"\n"+row3)

``````
1 Like

I have this problem any time I copy some code form Geany I have to play with indentations for some reason. Backspace + Tab seem to fix it. As for your problem, what is the console output when you use Replit?

Hello NikolaV, thank you for your time.
It’s showing a lot of errors but works fine on VsCode,
here’s the output:

``````python main.py
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
rootdir: /home/runner/boilerplate-arithmetic-formatter-3
collected 10 items

test_module.py FFFF...FFF                                                [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      1...----    -----' == '  3801      ...----    -----'
E         -   3801      123
E         ? -
E         +  3801      123
E           -    2    +  49
E           ------    -----

test_module.py:77: AssertionError
----------------------------- Captured stdout call -----------------------------

________________ 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...---    ------' == '  1         ...---    ------'
E         -   1         1
E         ? -
E         +  1         1
E           + 2    - 9380
E           ---    ------

test_module.py:77: AssertionError
----------------------------- Captured stdout call -----------------------------

________________ 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      38...----    -----' == '    3      3...----    -----'
E         -     3      3801      45      123
E         ? -
E         +    3      3801      45      123
E           + 855    -    2    + 43    +  49
E           -----    ------    ----    -----

test_module.py:77: AssertionError
----------------------------- Captured stdout call -----------------------------

________________ 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      380...---    ------' == '  11      38...---    ------'
E         -   11      3801      1      123         1
E         ? -
E         +  11      3801      1      123         1
E           +  4    - 2999    + 2    +  49    - 9380
E           ----    ------    ---    -----    ------

test_module.py:77: AssertionError
----------------------------- Captured stdout call -----------------------------

_______________________ 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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

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

def arithmetic_arranger(val, para2=False):
listlength= len(val)
row1=""
row2=""
row3=""
row4=""
space=""
space4=""
len4=0
spaceans=""
probnum=0
#---------------------------TESTING IF LIST IS GREATER THAN 5--------------------------------

if (listlength>5):
return("Error: Too many problems.")
#----------------------------SPLITTING STRINGS FROM THE LIST OF STRINGS -------------------------
print(" ",end="")
for i in val:
probnum=probnum+1
string= i.split()
val1=string[0]
val2=string[1]
val3=string[2]
#-------------------------TEST IF CONTAINS NUMBERS ONLY AND NOT GREATER THAN 4 DIGITS-------------------------------

for z in val:
try:
float(val1)
except ValueError:
return("Error: Numbers must only contain digits.")

if(len(val1)>4 or len(val3)>4):
return("Error: Numbers cannot be more than four digits.")

#-------------------------CASTING STRING TO INTEGER---------------------
int1= int(val1)
>           int3= int(val3)
E           ValueError: invalid literal for int() with base 10: '3g5'

arithmetic_arranger.py:38: ValueError
----------------------------- Captured stdout call -----------------------------

_______________ 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      98... 858     1028' == '    3      9... 858     1028'
E         -     3      988
E         ? -
E         +    3      988
E           + 855    +  40
E           -----    -----
E             858     1028

test_module.py:77: AssertionError
----------------------------- Captured stdout call -----------------------------

_______________ 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        ... 172     1028' == '   32       ... 172     1028'
E         -    32         1      45      123      988
E         ? -
E         +   32         1      45      123      988
E           - 698    - 3801    + 43    +  49    +  40
E           -----    ------    ----    -----    -----
E            -666     -3800      88      172     1028

test_module.py:77: AssertionError
----------------------------- Captured stdout call -----------------------------
 python main.py
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
rootdir: /home/runner/boilerplate-arithmetic-formatter-3
collected 10 items

test_module.py FFFF...FFF                                                [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      1...----    -----' == '  3801      ...----    -----'
E         -   3801      123
E         ? -
E         +  3801      123
E           -    2    +  49
E           ------    -----

test_module.py:77: AssertionError
----------------------------- Captured stdout call -----------------------------

________________ 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...---    ------' == '  1         ...---    ------'
E         -   1         1
E         ? -
E         +  1         1
E           + 2    - 9380
E           ---    ------

test_module.py:77: AssertionError
----------------------------- Captured stdout call -----------------------------

________________ 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      38...----    -----' == '    3      3...----    -----'
E         -     3      3801      45      123
E         ? -
E         +    3      3801      45      123
E           + 855    -    2    + 43    +  49
E           -----    ------    ----    -----

test_module.py:77: AssertionError
----------------------------- Captured stdout call -----------------------------

________________ 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      380...---    ------' == '  11      38...---    ------'
E         -   11      3801      1      123         1
E         ? -
E         +  11      3801      1      123         1
E           +  4    - 2999    + 2    +  49    - 9380
E           ----    ------    ---    -----    ------

test_module.py:77: AssertionError
----------------------------- Captured stdout call -----------------------------

_______________________ 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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

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

def arithmetic_arranger(val, para2=False):
listlength= len(val)
row1=""
row2=""
row3=""
row4=""
space=""
space4=""
len4=0
spaceans=""
probnum=0
#---------------------------TESTING IF LIST IS GREATER THAN 5--------------------------------

if (listlength>5):
return("Error: Too many problems.")
#----------------------------SPLITTING STRINGS FROM THE LIST OF STRINGS -------------------------
print(" ",end="")
for i in val:
probnum=probnum+1
string= i.split()
val1=string[0]
val2=string[1]
val3=string[2]
#-------------------------TEST IF CONTAINS NUMBERS ONLY AND NOT GREATER THAN 4 DIGITS-------------------------------

for z in val:
try:
float(val1)
except ValueError:
return("Error: Numbers must only contain digits.")

if(len(val1)>4 or len(val3)>4):
return("Error: Numbers cannot be more than four digits.")

#-------------------------CASTING STRING TO INTEGER---------------------
int1= int(val1)
>           int3= int(val3)
E           ValueError: invalid literal for int() with base 10: '3g5'

arithmetic_arranger.py:38: ValueError
----------------------------- Captured stdout call -----------------------------

_______________ 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      98... 858     1028' == '    3      9... 858     1028'
E         -     3      988
E         ? -
E         +    3      988
E           + 855    +  40
E           -----    -----
E             858     1028

test_module.py:77: AssertionError
----------------------------- Captured stdout call -----------------------------

_______________ 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        ... 172     1028' == '   32       ... 172     1028'
E         -    32         1      45      123      988
E         ? -
E         +   32         1      45      123      988
E           - 698    - 3801    + 43    +  49    +  40
E           -----    ------    ----    -----    -----
E            -666     -3800      88      172     1028

test_module.py:77: AssertionError
----------------------------- Captured stdout call -----------------------------

=========================== short test summary info ============================
FAILED test_module.py::test_template[test_two_problems_arrangement1] - Assert...
FAILED test_module.py::test_template[test_two_problems_arrangement2] - Assert...
FAILED test_module.py::test_template[test_four_problems_arrangement] - Assert...
FAILED test_module.py::test_template[test_five_problems_arrangement] - Assert...
FAILED test_module.py::test_template[test_only_digits] - ValueError: invalid ...
FAILED test_module.py::test_template[test_two_problems_with_solutions] - Asse...
FAILED test_module.py::test_template[test_five_problems_with_solutions] - Ass...
========================= 7 failed, 3 passed in 0.20s ==========================
``````

That looks like a lot of issues with spacing.

Am not sure but it seems identical to what is expected from the answer.
The above output is when the second parameter is false and below when its true.
The spacing and all appears normal, what can it be apart from that?

What are the new error messages? The error messages show the spacing descrepancies

Still the same errors, only 3 correct.
But for the test_two_problems_arrangement1, the answer in the above picture isn’t it correct?
Thanks

This says the spacing is wrong.

``````-   3801      123
? -
+  3801      123
``````

the - is what the test expected but didn’t find
the + is what the test found instead

Hello JeremyLT,
The problem has been solved.