Arithmetic Formatter four spaces issue

Hi. I am getting the four spaces issue in my code, (in pyCharm the output is correct but not in replit) because i have four spaces as characters printed after every line. I know they should not be there according to what i read in other posts, but i am not sure how to follow or solve this issue. Could i please get a hint about what is best according to my code?

here is my code so far:

def arithmetic_arranger(problems):
  arranged_problems = ""
  line1 = ""
  line2 = ""
  line3 = ""
  line4 = ""
  if len(problems) > 5: return "Error: Too many problems."
  for problem in problems:
    divided = problem.split()
    num1 = divided[0]
    oper = divided[1]
    num2 = divided[2]
    if len(num1) > 4 or len(num2) > 4 : return "Error: Numbers cannot be more than four digits."
    if not num1.isdigit(): return "Error: Numbers must only contain digits."
    if not num2.isdigit(): return "Error: Numbers must only contain digits."
    if oper not in "+-": return "Error: Operator must be '+' or '-'."
    if len(num1) > len(num2): lenspace = len(num1)
        lenspace = len(num2)
    raling = lenspace + 2
    if oper == "+": result = int(num1) + int(num2)
    else: result = int(num1) - int(num2)
    line1 += num1.rjust(raling) + "    "
    line2 += oper + " " + num2.rjust(raling-2) + "    "
    line3 += "-" * raling + "    "
    line4 += str(result).rjust(raling) + "    "
  arranged_problems = line1+"\n"+line2+"\n"+line3+"\n"+line4
  return arranged_problems

What error are you getting exactly?

Are you running the test module in PyCharm as well?

Here are the lines that are causing you to add 4 spaces at the end of each line.

You only want to add these 4 spaces when it is not the last problem.

Okay so you are adding 4 spaces to each problem in the line to get the correct seperation, but as you have no way of identifying the last problem in a row you end up with the extra 4 spaces, so what you need to do is either strip ,using one of pythons strip functions ,the trailing spaces before adding the “\n” or slice using [ : ] notation. Hope this steers you in the right direction

Thanks!. We fixed it :wink:
10 tests, 10 passed :wink:

Thanks! :wink: with your help guys, we fixed it. It’s a 10.