Arithmetic Formatter Project

Hello everyone, I’m stuck on the Arithmetic Formatter Project for a few days. I don’t know what’s wrong. Here’s my code:

def arithmetic_arranger(problems, show_answers=False):
    errorMessage = ''
    line1 = ''
    line2 = ''
    line3 = ''
    answers = ''
    if len(problems) > 5:
        return 'Error: Too many problems.'
    for problem in problems:
        split = problem.split(' ')
        operand1 = split[0]
        operator = split[1]
        operand2 = split[2]
        spaceAfter = (4 * ' ')
        spaceBefore = '  '
        if operator == '*' or operator == '/' in problem:
            return "Error: Operator must be '+' or '-'."
        if not operand1.isdigit() or not operand2.isdigit():
            return 'Error: Numbers must only contain digits.'
        if len(operand1) > 4 or len(operand2) > 4:
            errorMessage = 'Error: Numbers cannot be more than four digits.'
        maxlength = max(len(operand1), len(operand2))
        absolute = abs(len(operand1) - len(operand2))
        if len(operand1) > len(operand2):
            operand2  = (absolute * ' ') + operand2
        else:
            operand1 = (absolute * ' ') + operand1

        line1 += ('  {}{}'.format(spaceBefore, operand1,spaceAfter))
        line2 += ('{} {}{}'.format(spaceBefore,operator,operand2,spaceAfter)) 
        line3 += ('{}{}'.format(spaceBefore,((maxlength + 2) * '-'),spaceAfter))
        answers += ('  {}{}').format(eval(problem),spaceAfter)
 
    line1 += '\n'
    line2 += '\n'     
    problems = line1 + line2 + line3  
    if show_answers:
        problems += '\n'+ answers

    if errorMessage:
        return errorMessage
    return problems


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

Welcome to the forum @Khadojo1638

Your code:

    3801    123\n   -   2   + 49\n  ------  -----

Expected code:

3801      123\n-    2    +  49\n------    -----

Happy coding

Press f12 and check the browser dev tools console output for a more detailed error message