Arithmetic Formatter Calculation Problem

Tell us what’s happening:
When running the program checker for my project I am passing 8 of the 10 sets, but for some reason two of the sets incorrectly calculate the operation. This only occurs when I am running the program on the replit program not on my own IDE. As far as I can tell from the bug report my program is outputting an inverted operator (switching from + to - or vice versa). If I manually input the list it will give me the correct numbers as well. Any help on what could be causing this would be greatly appreciated!

Below are the tests I am still failing:

E         - 3800      88      172     1028
E         + 3800       2       74      948

E         -   858     1028
E         +  -852      948

Your code so far

def arithmetic_arranger(problems, display_results=False):
  topl = ''
  midl = ''
  linel = ''
  outputl = ''
  if len(problems) > 5:
    return "Error: Too many problems."
  else:
    lproblems = [problem.split(" ") for problem in problems]
    for problem in lproblems:
      if "*" in problem or "/" in problem:
        return "Error: Operator must be '+' or '-'."
      elif problem[0].isnumeric() is False or problem[-1].isnumeric() is False:
        return "Error: Numbers must only contain digits."
      elif len(problem[0]) > 4 or len(problem[-1]) > 4:
        return "Error: Numbers cannot be more than four digits."
      else:
        if problem[1] == "+":
          output = int(problem[0]) + int(problem[-1])
        else:
          output = int(problem[0]) - int(problem[-1])
        
       
        width = max(len(problem[0]), len(problem[-1]))+2
        topl += problem[0].rjust(width).rstrip() + "    "
        midl += problem[1] + problem[-1].rjust(width-1).rstrip() + "    "
        linel += ("-" * width) + "    "
        outputl += str(output).rjust(width) + "    "

    if display_results is True:
      arranged_problems = topl.rstrip()+"\n"+midl.rstrip()+"\n"+linel.rstrip()+"\n"+outputl.rstrip()
    else:
      arranged_problems = topl.rstrip()+"\n"+midl.rstrip()+"\n"+linel.rstrip()

    
  return arranged_problems

https://replit.com/@Ochem92/boilerplate-arithmetic-formatter-1#arithmetic_arranger.py

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36

Challenge: Arithmetic Formatter

Link to the challenge:

Solved my own problem reviewing it on here. I had called the output in a later line that was reassigning the variable. Gotta laugh!