Arithmetic Formatter Run Check Not Working

I was working on the Python project. Build an Arithmetic Formatter. Everything seems to be working and even when I tested the values on the run test it seems to not pass. I triple checked all my spacing and yet doesn’t seem to work. Help would be much appreciated.


def arithmetic_arranger(problems, show_answers=False):
    if len(problems) > 5:
        return 'Error: Too many problems.'
    
    #Adds equations to a list
    equations = []
    for eq in problems: #iterate equation strings
        equation = []
        longest_length = 0
        num = ''
        for i in eq: #iterate through each char in string
            if i.isalpha():
                return 'Error: Numbers must only contain digits.'
            if i == ' ':
                if not num == '':
                    equation.append(num)
                    #adding longest length
                    if len(num) > longest_length:
                        longest_length = len(num) 
                    num = ''
                    
            else:
                num += i
        equation.append(num)
        if len(num) > longest_length:
            longest_length = len(num)
        equation.append(longest_length)
        equations.append(equation)


    result = ""
    for eq in equations:
        #Error Checks
        if eq[1] == '+' or eq[1] =='-':
            pass
        else:
            return "Error: Operator must be '+' or '-'."
        if len(eq[2]) > 4 or len(eq[0]) > 4:
            return 'Error: Numbers cannot be more than four digits.'

    #Line 1
    for eq in equations:
        spaces = eq[3] + 2 - len(eq[0])
        result += (" " * spaces) + eq[0] + (" " * 4)

    #Line 2
    result += '\n'
    for eq in equations:
        result += eq[1]
        spaces = eq[3] + 1 - len(eq[2])
        result += (" " * spaces) + eq[2] + (" " * 4)

    #Line 3
    result += '\n'
    for eq in equations: 
        dash = eq[3] + 2
        result += ("-" * dash) + (" " * 4)

    #Answers
    if show_answers:
        result += '\n'
        for eq in equations:
            if eq[1] == '+':
                answer = int(eq[0]) + int(eq[2])
            else:
                answer = int(eq[0]) - int(eq[2])
            spaces = eq[3] + 2 - len(str(answer))
            result += (" " * spaces) + str(answer) + (" " * 4)
        
    return result

print(f'\n{arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"], True)}')

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

write it using repr so you have the output in the same format as it is written in the tests

print(repr(arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"], True)))

Thanks. This made me discover that I had some spacing issues after each line, but I was able to fix it.