Arithmetic Formatter in Python, Test don't pass

Tell us what’s happening:
My code passes 4 out of six tests, but when I see the output of the test it doesn’t pass, it seems that the outputs are equal, so it should pass. Am I missing something?
Your code so far

def arithmetic_arranger(*problems):
  import re
  if len(problems[0]) > 5:
    arranged_problems = "Error: Too many problems."
    return arranged_problems
  else:
    stringUp = ""
    stringDown = ""
    ralla = ""
    stringResult = ""
    for cadauno in problems[0]:
      stringtmp = cadauno.split()
      # Valida que los operadores sean "+" o "-"
      if re.search('[a-zA-Z]', cadauno):
        # Busca si hay letras en el arreglo, pues solo debe haber números.
        arranged_problems = "Error: Numbers must only contain digits."
        return arranged_problems
      if (stringtmp[1] != '+') and (stringtmp[1] != '-'):
        arranged_problems = "Error: Operator must be '+' or '-'."
        return arranged_problems
      else:
        if len(stringtmp[0]) > 4 or len(stringtmp[2]) > 4:
          # Valida que no sean mayores de 4 digitos
          return "Error: Numbers cannot be more than four digits."
        else:
          ancho = max(len(stringtmp[0]), len(stringtmp[2])) + 2
          stringUp = stringUp + stringtmp[0].rjust(ancho) + '    '
          stringDown = stringDown + stringtmp[1] + stringtmp[2].rjust(ancho - 1) + '    '
          ralla = ralla + ("_" * ancho) + '    '
          if len(problems) > 1:  # Valida si viene un segundo parámetro.
            # >>>>>>>>>>>>>>>  SUMAR EN LA TERCERA LINEA
            if stringtmp[1] == '+':
              stringResult = stringResult + str(int(stringtmp[0]) + int(stringtmp[2])).rjust(ancho) + '    '
            else:
              stringResult = stringResult + str(int(stringtmp[0]) - int(stringtmp[2])).rjust(ancho) + '    '
  arranged_problems = stringUp.rstrip() + '\n' + stringDown.rstrip() + '\n' + ralla.rstrip()
  if len(problems) > 1:
    arranged_problems = arranged_problems + '\n' + stringResult.rstrip()
  return arranged_problems

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36.

Challenge: Arithmetic Formatter

Link to the challenge:

What do the failing tests say?

I’ve edited your post 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.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

The first that fail:

Preformatted text

File "/home/runner/boilerplate-arithmetic-formatter-1/test_module.py", line 10, in test_arrangement
    self.assertEqual(actual, expected, 'Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]')
AssertionError: '    [34 chars]5    -    2    + 43    +  49\n_____    ______    ____    _____' != '    [34 chars]5    -    2    + 43    +  49\n-----    ------    ----    -----'
      3      3801      45      123
  + 855    -    2    + 43    +  49
- _____    ______    ____    _____+ -----    ------    ----    ----- : Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]

======================================================================

The second:

 File "/home/runner/boilerplate-arithmetic-formatter-1/test_module.py", line 39, in test_solutions
    self.assertEqual(actual, expected, 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with arithmetic problems and a second argument of `True`.')
AssertionError: '   3[59 chars] 49\n_____    ______    ____    _____\n -666  [21 chars] 172' != '   3[59 chars] 49\n-----    ------    ----    -----\n -666  [21 chars] 172'
     32         1      45      123
  - 698    - 3801    + 43    +  49
- _____    ______    ____    _____
+ -----    ------    ----    -----
   -666     -3800      88      172 : Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with arithmetic problems and a second argument of `True`.

It looks like it is a question of dashes vs underscores (- vs _)

1 Like

I can’t believe it!!. Thank you very much. I changed it and worked fine… I didn’t understand that in the error message!.