# Arrithmetic problems

hellou i stuck on one place and can help it to move it

`````` #problems = ["32 + 698", "3801 - 2", "45 + 43", "123 + 49"]

from pyrsistent import v

def arithmetic_arranger(problems, koniec=False):
cisla = list()
vysledok = '' #sucet cislo [1] a [2] rozdiel to iste
konecny_vysledok = ''

if len(problems) > 5 :
return 'Error: Too many problems.'
for problem in problems :
cisla.append(problem.split())
for cislo in cisla :
#print(cislo[1])
if len(cislo[0]) > 4 or len(cislo[2]) > 4 :
return 'Error: Numbers cannot be more than four digits.'
if cislo[1] != '+' and cislo[1] != '-' :
return "Error: Operator must be '+' or '-'."
if cislo[0].isnumeric()==False or cislo[2].isnumeric()==False :
return 'Error: Numbers must only contain digits.'
if cislo[1] == '-' :
vysledok = int(cislo[0]) - int(cislo[2])
elif cislo[1] == '+':
vysledok = int(cislo[0]) + int(cislo[2])
width = max(len(cislo[0]), len(cislo[2]))+ 2
#print(width,'---------')
druhy_riadok += cislo[1] + cislo[2].rjust(width-1)+'    '
konecny_vysledok += str(vysledok).rjust(width)+'    '
print(konecny_vysledok,'////////////////////')

=================================================================================== test session starts ====================================================================================
platform linux -- Python 3.8.10, pytest-4.6.9, py-1.8.1, pluggy-0.13.0
rootdir: /home/lukas/vscode freecode
collected 10 items

freecode arrithmetic/test_module.py FFFF......                                                                                                                                       [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      ...--    -----\n' == '  3801      1...----    -----'
E         Skipping 36 identical leading characters in diff, use -v to show
E         - --    -----
E         ?            -
E         + --    -----

freecode arrithmetic/test_module.py:77: AssertionError
----------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------
3799     ////////////////////
3799      172     ////////////////////
______________________________________________________________________ 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         ...-    ------\n' == '  1         1...---    ------'
E             1         1
E           + 2    - 9380
E         - ---    ------
E         ?              -
E         + ---    ------

freecode arrithmetic/test_module.py:77: AssertionError
----------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------
3     ////////////////////
3     -9379     ////////////////////
______________________________________________________________________ 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      3...--    -----\n' == '    3      38...----    -----'
E         Skipping 87 identical leading characters in diff, use -v to show
E         - --    -----
E         ?            -
E         + --    -----

freecode arrithmetic/test_module.py:77: AssertionError
----------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------
858     ////////////////////
858      3799     ////////////////////
858      3799      88     ////////////////////
858      3799      88      172     ////////////////////
______________________________________________________________________ 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      38...-    ------\n' == '  11      380...---    ------'
E         Skipping 111 identical leading characters in diff, use -v to show
E         - -    ------
E         ?            -
E         + -    ------

freecode arrithmetic/test_module.py:77: AssertionError
----------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------
15     ////////////////////
15       802     ////////////////////
15       802      3     ////////////////////
15       802      3      172     ////////////////////
15       802      3      172     -9379     ////////////////////
============================================================================ 4 failed, 6 passed in 0.06 seconds ============================================================================``````
``````assert '  11      38...-    ------\n' == '  11      380...---    ------'
``````

If you look closely, youâ€™ll notice that the left string ends end â€ś\nâ€ť while the right string doesnâ€™t.
So you got a newline character that shouldnâ€™t be there.

2 Likes

thanks a lot :)))))))

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