Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project

Tell us what’s happening:

I am working on the assigment for arithmetic formatter.
The code seems to work and the solution seems correct, yet the tests returns an error. Could someone tell me what the difference between my answer is and whats expected?

Your code so far

def arithmetic_arranger(problems, show_answers=False):
    errorMessage = ''
    line1 = ''
    line2 = ''
    line3 = ''
    answers = ''
    if len(problems) > 5:
        errorMessage = 'Error: Too many problems.'
    for problem in problems:
        split = problem.split(' ')
        operand1 = split[0]
        operator = split[1]
        operand2 = split[2]
        spaceAfter = (4 * ' ')
        if operator == '*' or operator == '/' in problem:
            errorMessage = "Error: Operator must be '+' or '-'."
        if not operand1.isdigit() or not operand2.isdigit():
            errorMessage = '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
            operand1 = (absolute * ' ') + operand1

        line1 += ('  {}{}'.format(operand1,spaceAfter))
        line2 += ('{} {}{}'.format(operator,operand2,spaceAfter)) 
        line3 += ('{}{}'.format(((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(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])}')

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:126.0) Gecko/20100101 Firefox/126.0

Challenge Information:

Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project

Check the browser console for a more detailed version of the test output

You have extra spaces at the end of each line

thank you very much,
i’ve managed to fix the issue

Hello! I have the same problem and I can’t solve it. Please tell me how you fixed the error?

In my code I added 4 spaces after each operand.
The problem was that the last operand in each line should not have 4 spaces after.

So instead I made it so it only added 4 spaces as long as it was not the last operand of the line, and if it was the last one, add a line break instead.

Hi Conte and welcome to our community!

If you have an issue with your own code, it’s best to open your own help topic for it.
Click on Get Help and Ask for Help to open up this window:

Try to give as much detail as possible and include your full code.

EDIT: Apologies, I note you have done so already. Please await a response in your own topic, thanks!

please open your own topic to ask for help, copying other peoples code is againt the Academic Honesty Pledge