Arithmetic Formatter Project

first_list=[]
second_list=[]
list_first=[]
list_symbol=[]
list_sec=[]
append_list=[]
append_list2=[]
append_list3=[]



def space(val, list, sec_operand, append_list):
  a=list.index(val)
  if a in append_list:
    a=list.index(val, a+1)
    append_list.append(a)
  else:
    append_list.append(a)
  if len(list[a])>(len(sec_operand[a])) and list==list_first:
    num_fir=0
    return num_fir


  elif (len(list[a]))>(len(sec_operand[a])) and list==list_sec:
    num_sec=0 
    return num_sec


  elif ((len(sec_operand[a]))>(len(list[a]))) and (list==list_first):
    num_fir=(len(sec_operand[a])-len(list[a]))
    return num_fir

  elif ((len(sec_operand[a]))==(len(list[a]))) and (list==list_first): 
    num_fir=0
    return num_fir

  elif (len(sec_operand[a])>((len(list[a])))) and (list==list_sec):
    num_sec=(-(len(list[a]))+(len(sec_operand[a])))
    return num_sec

  elif (len(sec_operand[a])==((len(list[a])))) and (list==list_sec):
    num_sec=0
    return num_sec











def arithmetic_arranger(problems, bool=False):
  if len(problems)>5:
      return "Error: To many problems."
      quit()# works
  for calculation in problems:
    if "-"  in calculation:
      pass
    elif "+" in calculation:
      pass
    else:
      return 'Error: Operator must be "+" or "-"'
      quit()# works
    parts=calculation.split()
    if len(parts[0])>4:
      return "Error: Numbers cannot be more than four digits."
    if len(parts[2])>4:
      return "Error: Numbers cannot be more than four digits."
    list_first.append(parts[0])
    list_symbol.append(parts[1])
    list_sec.append(parts[2]) 



  for val in list_first:
    for digit in val:
      if digit in ["0","1","2","3","4","5","6","7","8","9"]:
        pass
      else:
        return "Error: Numbers must only conatain digits."
        



  for number in list_sec:
    for son in number:
      if son in ["0","1","2","3","4","5","6","7","8","9"]:
        pass
      else:
        return "Error:Numbers must only conatain digits."
        quit()



  counter=0
  first_line=""
  for real_val in list_first:
    num_first=space(real_val, list_first, list_sec, first_list)
    num=num_first+4
    if counter!=0:
      num=4+num_first
      first_line+=" "*(num)+"  "+real_val
    else:
      num=num_first
      first_line=" "*(num)+"  "+real_val
    counter+=1    
    
  first_line+="\n"
  counter=0



  for real_val in list_sec:
    a=list_sec.index(real_val)
    if a in append_list2:
      a=list_sec.index(real_val, a+1)
      append_list2.append(a)
    else:
      append_list2.append(a)
    num_second=space(real_val, list_sec, list_first, second_list)
    if list_symbol[a]=="+":
      operation="+"
    elif list_symbol[a]=="-":
      operation="-"
    if counter!=0:
      num=num_second
      first_line+=" "*4+f"{operation}"+" "+" "*num+real_val
    else:
      num=num_second
      first_line+=f"{operation}"+" "+" "*num+real_val
    counter+=1
  first_line+="\n"




  for real_val in list_sec:
    a=list_sec.index(real_val)
    if a in append_list:
      a=list_sec.index(real_val, a+1)
      append_list.append(a)
    else:
      append_list.append(a)
    nnn=max(len(list_sec[a]),(len(list_first[a])))
    lines=nnn+2
    first_line+="-"*lines+" "*4
  



  if bool==True:
    first_line+="\n"
    for real_val in list_sec:
      a=list_sec.index(real_val)
      if a in append_list3:
        a=list_sec.index(real_val, a+1)
        append_list3.append(a)
      else:
        append_list3.append(a)
      if list_symbol[a]=="+":
        lines=max(len(list_first[a]),len(list_sec[a]))+2
        sum=str(int(list_sec[a])+int(list_first[a]))
        num=lines-len(sum)
        first_line+=" "*num+sum+" "*4
      else:
        subtraction=str(int(list_first[a])-int(list_sec[a]))
        lines=max(len(list_sec[a]),len(list_first[a]))+2
        num=lines-len(subtraction)
        first_line+=" "*num+subtraction+" "*4
  return first_line


What’s the problem in this code?

Error:

=========================== test session starts ============================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /home/runner/boilerplate-arithmetic-formatter/venv/bin/python3
cachedir: .pytest_cache
rootdir: /home/runner/boilerplate-arithmetic-formatter
collected 10 items                                                         

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

    @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: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
arithmetic_arranger.py:101: in arithmetic_arranger
    num_first=space(real_val, list_first, list_sec, first_list)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

val = '32', list = ['32', '3801', '45', '123', '3801', '123']
sec_operand = ['698', '2', '43', '49', '2', '49']
append_list = [0, 1, 2, 3]

    def space(val, list, sec_operand, append_list):
      a=list.index(val)
      if a in append_list:
>       a=list.index(val, a+1)
E       ValueError: '32' is not in list

arithmetic_arranger.py:15: ValueError
______________ 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)

test_module.py:76: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
arithmetic_arranger.py:101: in arithmetic_arranger
    num_first=space(real_val, list_first, list_sec, first_list)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

val = '32', list = ['32', '3801', '45', '123', '3801', '123', ...]
sec_operand = ['698', '2', '43', '49', '2', '49', ...]
append_list = [0, 1, 2, 3]

    def space(val, list, sec_operand, append_list):
      a=list.index(val)
      if a in append_list:
>       a=list.index(val, a+1)
E       ValueError: '32' is not in list

arithmetic_arranger.py:15: ValueError
______________ 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)

test_module.py:76: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
arithmetic_arranger.py:101: in arithmetic_arranger
    num_first=space(real_val, list_first, list_sec, first_list)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

val = '32', list = ['32', '3801', '45', '123', '3801', '123', ...]
sec_operand = ['698', '2', '43', '49', '2', '49', ...]
append_list = [0, 1, 2, 3]

    def space(val, list, sec_operand, append_list):
      a=list.index(val)
      if a in append_list:
>       a=list.index(val, a+1)
E       ValueError: '32' is not in list

arithmetic_arranger.py:15: ValueError
______________ 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)

test_module.py:76: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
arithmetic_arranger.py:101: in arithmetic_arranger
    num_first=space(real_val, list_first, list_sec, first_list)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

val = '32', list = ['32', '3801', '45', '123', '3801', '123', ...]
sec_operand = ['698', '2', '43', '49', '2', '49', ...]
append_list = [0, 1, 2, 3]

    def space(val, list, sec_operand, append_list):
      a=list.index(val)
      if a in append_list:
>       a=list.index(val, a+1)
E       ValueError: '32' is not in list

arithmetic_arranger.py:15: ValueError
__________________ test_template[test_too_many_problems] ___________________

arguments = [['44 + 815', '909 - 2', '45 + 43', '123 + 49', '888 + 40', '653 + 87']]
expected_output = 'Error: Too many problems.'
fail_message = 'Expected calling "arithmetic_arranger()" with more than five problems to return "Error: Too many problems."'

    @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 calling "arithmetic_arranger()" with more than five problems to return "Error: Too many problems."
E       assert 'Error: To many problems.' == 'Error: Too many problems.'
E         - Error: Too many problems.
E         ?          -
E         + Error: To many problems.

test_module.py:77: AssertionError
__________________ test_template[test_incorrect_operator] __________________

arguments = [['3 / 855', '3801 - 2', '45 + 43', '123 + 49']]
expected_output = "Error: Operator must be '+' or '-'."
fail_message = 'Expected calling "arithmetic_arranger()" with a problem that uses the "/" operator to return "Error: Operator must be \'+\' or \'-\'."'

    @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 calling "arithmetic_arranger()" with a problem that uses the "/" operator to return "Error: Operator must be '+' or '-'."
E       assert 'Error: Operator must be "+" or "-"' == "Error: Operator must be '+' or '-'."
E         - Error: Operator must be '+' or '-'.
E         ?                         ^ ^    ^ ^^
E         + Error: Operator must be "+" or "-"
E         ?                         ^ ^    ^ ^

test_module.py:77: AssertionError
_____________________ 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)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected calling "arithmetic_arranger()" with a problem that contains a letter character in the number to return "Error: Numbers must only contain digits."
E       assert 'Error:Numbers must only conatain digits.' == 'Error: Numbers must only contain digits.'
E         - Error: Numbers must only contain digits.
E         ?       -
E         + Error:Numbers must only conatain digits.
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 'Error:Numbers must only conatain digits.' == '    3      988\n+ 855    +  40\n-----    -----\n  858     1028'
E         + Error:Numbers must only conatain digits.
E         -     3      988
E         - + 855    +  40
E         - -----    -----
E         -   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 'Error:Numbers must only conatain digits.' == ('   32         1      45      123      988\n'\n '- 698    - 3801    + 43    +  49    +  40\n'\n '-----    ------    ----    -----    -----\n'\n ' -666     -3800      88      172     1028')
E         + Error:Numbers must only conatain digits.
E         -    32         1      45      123      988
E         - - 698    - 3801    + 43    +  49    +  40
E         - -----    ------    ----    -----    -----
E         -  -666     -3800      88      172     1028

test_module.py:77: AssertionError
========================= short test summary info ==========================
FAILED test_module.py::test_template[test_two_problems_arrangement1] - Va...
FAILED test_module.py::test_template[test_two_problems_arrangement2] - Va...
FAILED test_module.py::test_template[test_four_problems_arrangement] - Va...
FAILED test_module.py::test_template[test_five_problems_arrangement] - Va...
FAILED test_module.py::test_template[test_too_many_problems] - AssertionE...
FAILED test_module.py::test_template[test_incorrect_operator] - Assertion...
FAILED test_module.py::test_template[test_only_digits] - AssertionError: ...
FAILED test_module.py::test_template[test_two_problems_with_solutions] - ...
FAILED test_module.py::test_template[test_five_problems_with_solutions]
======================= 9 failed, 1 passed in 0.42s ========================

I edited your post so we can read the list of errors easier.

You need to look through the errors one by one and fix them in your code.

For eg. here is one of the errors reported:

Notice that it is saying that it was expecting you to output a string that starts with the words “Error: Too” and instead you used “Error: To”

Another error below that is shown:

E         - Error: Operator must be '+' or '-'.
E         ?                         ^ ^    ^ ^^
E         + Error: Operator must be "+" or "-"
E         ?                         ^ ^    ^ ^

And again it says it is expecting a specific error message but you outputted a different one (you have the wrong quote symbols)

And the next one says you have a spelling error.
And the next one says the output was incorrect.

So you should try to test your code independently from the test suite and make sure it is working before running the test suite. Then if the test suite fails you can review the errors to see why.

Thank you for help.


first_list=[]
second_list=[]
list_first=[]
list_symbol=[]
list_sec=[]
append_list=[]
append_list2=[]
append_list3=[]



def space(val, list, sec_operand, append_list):
  a=list.index(val)
  if a in append_list:
    a=list.index(val, a+1)
    append_list.append(a)
  else:
    append_list.append(a)
  if len(list[a])>(len(sec_operand[a])) and list==list_first:
    num_fir=0
    return num_fir


  elif (len(list[a]))>(len(sec_operand[a])) and list==list_sec:
    num_sec=0 
    return num_sec


  elif ((len(sec_operand[a]))>(len(list[a]))) and (list==list_first):
    num_fir=(len(sec_operand[a])-len(list[a]))
    return num_fir

  elif ((len(sec_operand[a]))==(len(list[a]))) and (list==list_first): 
    num_fir=0
    return num_fir

  elif (len(sec_operand[a])>((len(list[a])))) and (list==list_sec):
    num_sec=(-(len(list[a]))+(len(sec_operand[a])))
    return num_sec

  elif (len(sec_operand[a])==((len(list[a])))) and (list==list_sec):
    num_sec=0
    return num_sec


def arithmetic_arranger(problems, bool=False):
  if len(problems)>5:
      return 'Error: Too many problems.'
      quit()# works
  for calculation in problems:
    if "-"  in calculation:
      pass
    elif "+" in calculation:
      pass
    else:
      return "Error: Operator must be '+' or '-'."
      quit()# works
    parts=calculation.split()
    if len(parts[0])>4:
      return "Error: Numbers cannot be more than four digits."
    if len(parts[2])>4:
      return "Error: Numbers cannot be more than four digits."
    list_first.append(parts[0])
    list_symbol.append(parts[1])
    list_sec.append(parts[2]) 



  for val in list_first:
    for digit in val:
      if digit in ["0","1","2","3","4","5","6","7","8","9"]:
        pass
      else:
        return 'Error: Numbers must only contain digits.'
        



  for number in list_sec:
    for son in number:
      if son in ["0","1","2","3","4","5","6","7","8","9"]:
        pass
      else:
        return 'Error: Numbers must only contain digits.'
        



  counter=0
  first_line=''
  for real_val in list_first:
    num_first=space(real_val, list_first, list_sec, first_list)
    num=num_first+4
    if counter!=0:
      num=4+num_first
      first_line+=" "*(num)+"  "+real_val
    else:
      num=num_first
      first_line=" "*(num)+"  "+real_val
    counter+=1    
  
  first_line+="\n"
  counter=0


  
  for real_val in list_sec:
    a=list_sec.index(real_val)
    if a in append_list2:
      a=list_sec.index(real_val, a+1)
      append_list2.append(a)
    else:
      append_list2.append(a)
    num_second=space(real_val, list_sec, list_first, second_list)
    if list_symbol[a]=="+":
      operation="+"
    elif list_symbol[a]=="-":
      operation="-"
    if counter!=0:
      num=num_second
      first_line+=" "*4+f"{operation}"+" "+" "*num+real_val
    else:
      num=num_second
      first_line+=f"{operation}"+" "+" "*num+real_val
    counter+=1
  first_line+="\n"



  counter2=0
  for real_val in list_sec:
    a=list_sec.index(real_val)
    if a in append_list:
      a=list_sec.index(real_val, a+1)
      append_list.append(a)
    else:
      append_list.append(a)
    nnn=max(len(list_sec[a]),(len(list_first[a])))
    lines=nnn+2
    if counter2!=0:
      first_line+=" "*4+"-"*lines
    else:
      first_line+="-"*lines
      counter2+=1



  if bool==True:
    first_line+="\n"
    for real_val in list_sec:
      a=list_sec.index(real_val)
      if a in append_list3:
        a=list_sec.index(real_val, a+1)
        append_list3.append(a)
      else:
        append_list3.append(a)
      if list_symbol[a]=="+":
        lines=max(len(list_first[a]),len(list_sec[a]))+2
        sum=str(int(list_sec[a])+int(list_first[a]))
        num=lines-len(sum)
        first_line+=" "*num+sum+" "*4
      else:
        subtraction=str(int(list_first[a])-int(list_sec[a]))
        lines=max(len(list_sec[a]),len(list_first[a]))+2
        num=lines-len(subtraction)
        first_line+=" "*num+subtraction+" "*4
  return first_line

Still the program gives 5 fail message.

 python3 main.py
============================ test session starts ============================
platform linux – Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 – /home/runner/boilerplate-arithmetic-formatter-1/venv/bin/python3
cachedir: .pytest_cache
rootdir: /home/runner/boilerplate-arithmetic-formatter-1
collected 10 items

test_module.py::test_template[test_two_problems_arrangement1] PASSED [ 10%]
test_module.py::test_template[test_two_problems_arrangement2] FAILED [ 20%]
test_module.py::test_template[test_four_problems_arrangement] FAILED [ 30%]
test_module.py::test_template[test_five_problems_arrangement] FAILED [ 40%]
test_module.py::test_template[test_too_many_problems] PASSED [ 50%]
test_module.py::test_template[test_incorrect_operator] PASSED [ 60%]
test_module.py::test_template[test_too_many_digits] PASSED [ 70%]
test_module.py::test_template[test_only_digits] PASSED [ 80%]
test_module.py::test_template[test_two_problems_with_solutions] FAILED [ 90%]
test_module.py::test_template[test_five_problems_with_solutions] FAILED [100%]

================================= FAILURES ==================================
_______________ 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)

test_module.py:76:


arithmetic_arranger.py:93: in arithmetic_arranger
num_first=space(real_val, list_first, list_sec, first_list)


val = ‘3801’, list = [‘3801’, ‘123’, ‘1’, ‘1’]
sec_operand = [‘2’, ‘49’, ‘2’, ‘9380’], append_list = [0, 1]

def space(val, list, sec_operand, append_list):
  a=list.index(val)
  if a in append_list:
  a=list.index(val, a+1)

E ValueError: ‘3801’ is not in list

arithmetic_arranger.py:16: ValueError
_______________ 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 (’ 3801 123 1 1 3 3801 45 123\n’\n ‘+ 2 + 49 + 2 - 9380 + 855 + 2 + 43 + 49\n’\n ‘— ----- — ------ ----- — ---- -----’) == (’ 3 3801 45 123\n’\n ‘+ 855 - 2 + 43 + 49\n’\n ‘----- ------ ---- -----’)
E - 3 3801 45 123
E - + 855 - 2 + 43 + 49
E - ----- ------ ---- -----
E + 3801 123 1 1 3 3801 45 123
E + + 2 + 49 + 2 - 9380 + 855 + 2 + 43 + 49
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)

test_module.py:76:


arithmetic_arranger.py:93: in arithmetic_arranger
num_first=space(real_val, list_first, list_sec, first_list)


val = ‘3’, list = [‘3801’, ‘123’, ‘1’, ‘1’, ‘3’, ‘3801’, …]
sec_operand = [‘2’, ‘49’, ‘2’, ‘9380’, ‘855’, ‘2’, …]
append_list = [0, 1, 5, 7, 2, 3, …]

def space(val, list, sec_operand, append_list):
  a=list.index(val)
  if a in append_list:
  a=list.index(val, a+1)

E ValueError: ‘3’ is not in list

arithmetic_arranger.py:16: ValueError
______________ 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 ‘Error: Numbers must only contain digits.’ == ’ 3 988\n+ 855 + 40\n----- -----\n 858 1028’
E + Error: Numbers must only contain digits.
E - 3 988
E - + 855 + 40
E - ----- -----
E - 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 ‘Error: Numbers must only contain digits.’ == (’ 32 1 45 123 988\n’\n ‘- 698 - 3801 + 43 + 49 + 40\n’\n ‘----- ------ ---- ----- -----\n’\n ’ -666 -3800 88 172 1028’)
E + Error: Numbers must only contain digits.
E - 32 1 45 123 988
E - - 698 - 3801 + 43 + 49 + 40
E - ----- ------ ---- ----- -----
E - -666 -3800 88 172 1028

test_module.py:77: AssertionError
========================== short test summary info ==========================
FAILED test_module.py::test_template[test_two_problems_arrangement2] - Val…
FAILED test_module.py::test_template[test_four_problems_arrangement] - Ass…
FAILED test_module.py::test_template[test_five_problems_arrangement] - Val…
FAILED test_module.py::test_template[test_two_problems_with_solutions] - A…
FAILED test_module.py::test_template[test_five_problems_with_solutions] - …
======================== 5 failed, 5 passed in 0.31s ========================

Here is a full code that can help you out.
mod edit: solution removed

hi there,

Sharing code for projects counts as breaking our academic honesty policy and can result in losing the certificate. Please do not do this again.

thank you