Calling 911 - Arithmetic Arranger Help

my code seems to work fine on command line but its failing fcc test on repl.it.
ive tried but i cant figure it out.

def arithmetic_arranger(problems, solved=True):

    line1 = ''
    line2 = ''
    line3 = ''
    line4 = ''
    # To check for number of problems
    if len(problems) > 5:
        return "Error: Too many prolems"


    for z, problem in enumerate(problems):
        num1, op, num2 = problem.split()
#Test for operator
        if op =='*' or op == '/':
            return "Error: operator must be '+' or '-'"
    #test for digits
        if num1.isdigit() == False or num2.isdigit() == False:
            return "Error: Numbers must only contain digits"
    #test for lenght of Numbers
        if len(num1) > 4 or len(num2) > 4:
            return "rror: Numbers can not be more than four digits"

        if op == '+':
            result = int(num1) + int(num2)
        elif op == '-':
            result = int(num1) - int(num2)

    #space setup
        len_num1 = len(num1)
        len_num2 = len(num2)
        space = max(len_num1, len_num2) + 2
        extra_space = '    '
    #line arrange
        line1 += num1.rjust(space)
        line2 += op + num2.rjust(space -1)
        line3 += "-" * space
        line4 += str(result).rjust(space)
        if z < len(problem) - 1:
            line1 += extra_space
            line2 += extra_space
            line3 += extra_space
            line4 += extra_space
    if solved:
        solution = line1 + '\n' + line2 + '\n' + line3 + '\n' + line4
    else:
        solution = line1 + '\n' + line2 + '\n' + line3
    return solution

this is the link to the test https://repl.it/@seunlaww/SnivelingWateryArchives-1

read the errors, it says what’s expected and what’s being returned.

1 Like

thank you. i have fixed that but its still failling two tests

def arithmetic_arranger(problems, solved = False):
    line1 = ''
    line2 = ''
    line3 = ''
    line4 = ''
    # To check for number of problems
    if len(problems) > 5:
        return "Error: Too many problems."


    for z, problem in enumerate(problems):
        num1, op, num2 = problem.split()
#Test for operator
        if op =='*' or op == '/':
            return "Error: Operator must be '+' or '-'."
    #test for digits
        if num1.isdigit() == False or num2.isdigit() == False:
            return "Error: Numbers must only contain digits."
    #test for lenght of Numbers
        if len(num1) > 4 or len(num2) > 4:
            return "Error: Numbers cannot be more than four digits."

        if op == '+':
            result = int(num1) + int(num2)
        elif op == '-':
            result = int(num1) - int(num2)

    #space setup
        len_num1 = len(num1)
        len_num2 = len(num2)
        space = max(len_num1, len_num2) + 2
        extra_space = '    '
    #line arrange
        line1 += num1.rjust(space)
        line2 += op + num2.rjust(space -1)
        line3 += "-" * space
        line4 += str(result).rjust(space)
        if z < len(problem) - 1:
            line1 += extra_space
            line2 += extra_space
            line3 += extra_space
            line4 += extra_space
    if solved:
        solution = line1 + '\n' + line2 + '\n' + line3 + '\n' + line4
    else:
        solution = line1 + '\n' + line2 + '\n' + line3

    return solution

the minus signs in the line starting with ? indicate characters that are present in your output but should not be there: it seems you have some extra spaces

image

here is what i did, line two has an extra space and in the length check, i replaced len(problem) with len(problems).

thanks for the reply, it really helps