Can't figure out errors in my Arithmetic Formatter Code

def arithmetic_arranger(problems, showSol=False):
    letters = "abcdefghijklmnopqrstuvwxyz"
    firstline = ""
    secondline = ""
    thirdline = ""
    fourthline = ""
    first = True
    if len(problems) > 5:
        return "Error: Too many problems."
    for i in problems:
        express = i.split()
        first_arg = express[0]
        first_arg_length = len(first_arg)
        op = express[1]
        second_arg = express[2]
        second_arg_length = len(second_arg)
        if "+" not in op and "-" not in op:
            return "Error: Operator must be '+' or '-'."
        for letter in letters:
            if letter in first_arg or letter in second_arg:
                return "Error: Numbers must only contain digits."
        if first_arg_length > 4 or second_arg_length > 4:
            return "Error: Numbers cannot be more than four digits."
        first_arg_int = int(first_arg)
        second_arg_int = int(second_arg)
        bigger = max(len(first_arg), len(second_arg))
        if first:
            firstline += first_arg.rjust(bigger + 2)
            secondline += op + " " + second_arg.rjust(bigger)
            thirdline = "".rjust(bigger + 2, '-')
            if(showSol):
                if(op == '+'):
                    fourthline += str(first_arg_int + second_arg_int).rjust(bigger + 2)
                else:
                    fourthline += str(first_arg_int - second_arg_int).rjust(bigger + 2)
            first = False
        else:
            firstline += first_arg.rjust(bigger + 6)
            secondline += op.rjust(5) + " " + second_arg.rjust(bigger)
            thirdline += "    " + "".rjust(bigger+2, "-")
            if op == "+":
                fourthline += "    " + str(first_arg_int + second_arg_int).rjust(bigger + 2)
            else:
                fourthline += "    " + str(first_arg_int - second_arg_int).rjust(bigger + 2)
    if not showSol:
        fourthline = ""
    sol = firstline + "\n" + secondline + "\n" + thirdline + "\n" + fourthline + "\n"
    return sol

and here is the link to my replit: https://replit.com/@HarshilAv/boilerplate-arithmetic-formatter-1#arithmetic_arranger.py

When I try to test the errors, my output and the expected output look the same to me

You have extra newlines at the end of your output. When answers are displayed there are two extra and when they are not there’s one extra.

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