Arithmetic Formatter Test failure

Hi All,

My code is running ok and passes all the tests when i run them manually but fails with the test module.

Any advice or pointers as to why?

def arithmetic_arranger(problems):

arranged_problems=0
arranged_problems=[]



        
## Length test
if len(problems)>5:
    print("Error: Too many problems.")


else:
    for i in problems:
        x=i.split()
        n1=(x[0])
        symbol= x[1]
        n2=(x[2])

        ## operator test
        if symbol == "*" or symbol == "/":
            print("Error: Operator must be '+' or '-'.")


        else:

            fstlength=len(n1)

            sndlength=len(n2)

            ## len test
            if fstlength>4 or sndlength>4:
                print("Error: Numbers cannot be more than four digits.")
                break
            else:


                ## digit test
                if n1.isalpha() or n2.isalpha() == False:
                    pass
                else:
                    print("Error: Numbers must only contain digits.")

                n1=int(n1)
                n2=int(n2)

            ## calculation
                if symbol == "+":
                    answer = n1+n2
                else:
                    answer= n1-n2

            ## display
                dashsize=0
                if fstlength<sndlength:
                    dashsize=sndlength+2
                else:
                    dashsize = fstlength+2

                dashes=str("-"*dashsize)
                n3=str(n1)
                n4=str(n2)
                final=str(answer)
                
                line1=str(n3.rjust(dashsize))
                line2=str(symbol)+str(n4.rjust(dashsize-1))
                line3=dashes
                line4=str(final.rjust(dashsize))
                
                ##print("\nXXXXXX\n "+ x+" \nXXXXXXX\n")
                arranged_problems.append(line1)
                arranged_problems.append(line2)
                arranged_problems.append(line3)
                arranged_problems.append(line4)

top =str(arranged_problems[0]+"    "+arranged_problems[4]+"    "+arranged_problems[8]+"    "+arranged_problems[12]+"\n")
bot =str(arranged_problems[1]+"    "+arranged_problems[5]+"    "+arranged_problems[9]+"    "+arranged_problems[13]+"\n")
das =str(arranged_problems[2]+"    "+arranged_problems[6]+"    "+arranged_problems[10]+"    "+arranged_problems[14]+"\n")
ans =str(arranged_problems[3]+"    "+arranged_problems[7]+"    "+arranged_problems[11]+"    "+arranged_problems[15]+"\n")
arranged_problems=top+bot+das+ans
return arranged_problems

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 Edg/85.0.564.41.

Challenge: Arithmetic Formatter

Link to the challenge:

can you share your repl? what’s the test output?

what’s your fourth line?
you just need a line for first number, a line for second number, and a line for the dashes

I have modified my code since I originally posted and now only have two test to pass (forgot to add in the display answer option argument code)

I also tidied up my error coding

my fourth line is for the solutions

I think both test failures come back to my answer string formatting but I cant see in the error return code where the issues are

I have manged to get this to work now. It isn’t an elegant solution but it passes the tests