Only one problem showing on Build an Arithmetic Formatter Project

I’ve been working on this project for some time now and I have the formatting and structure of this project down, but when it comes to displaying the rest of the math problems within this project it only keeps showing the first problem and I’m confused as to why it’s doing that as the code should display the rest of the problems and have double and tripled checked my code to see what the issue is and I can’t figure out what the problem is, and I’ll link my code within this post as well down below:

def arithmetic_arranger(problems, show_answers=False):
#1 Check the length of the parameter
    if len(problems) > 5:
        return "Error: Too many problems."

#2 Check the operand
    operators = []
    for problem in problems:
        array = problem.split()
        operators.append(array[1])

    for operator in operators:
        if operator in ['*', '/']:
            return "Error: Operator must be '+' or '-'."
    
#3 Check for non-digits
    numbers = []
    for problem in problems:
        array = problem.split()
        numbers.append(array[0])
        numbers.append(array[2])
    
    for number in numbers:
        if not number.isdigit():
            return "Error: Numbers must only contain digits."
#4 Check Operand Length        
        elif len(number) > 4:
            return "Error Numbers can not be more than four digits."

#5 Evaluation
    answers = []
    top_row = ''
    bottom_row = ''
    answer_row = ''
    dashes = ''

    for i in range(0, len(number), 2):
        num1 = int(numbers[i])
        num2 = int(numbers[i + 1])
        operator = operators[i // 2]

        if operator == '+':
            result = num1 + num2
        else:
            result = num1 - num2
        answers.append(result)

    

#6 Formatting problem rows
        space_width = max(len(numbers[i]), len(numbers[i + 1])) + 2
        top_row += numbers[i].rjust(space_width)
        bottom_row += operator + numbers[i + 1].rjust(space_width - 1)
        dashes += '-' * space_width

#7 Spacing between problems
        if i != len(numbers) - 2:
            top_row += ' ' * 4
            bottom_row +=  ' ' * 4
            dashes +=  ' ' * 4
    
#8 Formatting answers row
    for i in range(len(answers)):
        space_width = max(len(numbers[2 * i]), len(numbers[2 * i + 1])) + 2
        answer_row += str(answers[i]).rjust(space_width)

#9 Spacing between answers
        if i != len(answers) - 1:
            answer_row += ' ' * 4

#10 Final Arrangement and return
    if show_answers:
        arranged_problems = '\n'.join((top_row, bottom_row, dashes, answer_row))
    else:
        arranged_problems = '\n'.join((top_row, bottom_row, dashes,))


        print(answer_row)
    
    return arranged_problems

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

Hi there and welcome to our community!

You need to correct something in this line:

for i in range(0, len(number), 2):

It’s a small error, but fixing it will pass all but one of the tests for this project.

Also, the only test which fails when you have fixed the above is only failing because the error string which you’re returning does not exactly match the requirements (so it’s also a very easy fix).

1 Like

That definitely helped fixed the majority of the tests, but I for the life of me can’t figure out what is causing that one test not be corrected, im changing the returning variable as I thought that might be the issue, checked the syntax and the grammer of the error message but it’s still not coming back as correct

Took me a few days to realize it but i was missing a colon, thanks for the help man!

you should code in like pycharm for the projects. If you’re missing any syntax like commas it’s easier to see because it’ll tell you right away.
After you can just paste the code over to freecodecamp.