Need help with Python Arithmetic Formatter

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

def arithmetic_arranger(problems, results = False):

    first = ""
    second = ""
    lines = ""
    sumx = ""    
    if len(problems) >= 6:
      return "Error: Too many problems."

    for v in problems:
      a = v.split()
      firstsnum = a[0]
      operator = a[1]
      secondnum = a[2]

      if (len(firstsnum) >= 5 or len(secondnum) >= 5) :
        return "Error: Numbers cannot be more than four digits. "

      if not firstsnum.isnumeric() or not secondnum.isnumeric():
        return "Error: Numbers must only contain digits"
      if ( operator == '-' or operator == '+' ) :
        if operator == "-":
          sums = str(int(firstsnum) - int(secondnum))
          sums = str(int(firstsnum) + int(secondnum))
        length = max(len(firstsnum), len(secondnum)) + 2
        top = str(firstsnum).rjust(length)
        bottom = operator + str(secondnum).rjust(length - 1)
        line = ""
        res = str(sums).rjust(length)
        for s in range(length):
            line += "-"
            if v != problems[-1]:
              first += top + '    '
              second += bottom + '    '
              lines += line + '    '
              sumx += res + '    '
              first += top
              second += bottom
              lines += line
              sumx += res
            return "Error: Operator must be '+' or '-'. "

    if results:
      arranged_problems = first + "\n" + second + "\n" + lines + "\n" + sumx
     arranged_problems = first + "\n" + second + "\n" + lines

    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/97.0.4692.99 Safari/537.36

Challenge: Arithmetic Formatter

Link to the challenge:

You should look at the test output. There is a lot, so just look at one test at a time. Many of the tests are currently failing because you are returning incorrect messages. They have to be identical to the ones in the spec or the tests will fail.

On the formatting tests, your output has multiple versions of every problem, so some loop is not correct. The main problem is that there is inconsistent indentation in the code (some 2, some 4) and that is leading to confusion. While I could fix the code, I can’t help you debug because I can’t always tell which code you have indented to which level.

So fix the messages, fix the indentation, return one version of each problem, and then make sure that you have the correct number of spaces.

Hi, thanks a lot for the help but after I did what u said about the indentation i got this error which I can’t understand, does that mean i have to rewrite code or something?

Look at the bottom where the lines begin with E for the error. Pay attention to the one with \import pytest and the backslash. Looks like there is more error message below that that is cut off in the image that probably says something about a syntax error.

Always best to post errors as text in code blocks or post a link to a repl (like at to make debugging easier.

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