Scientific Computing with Python Projects - Arithmetic Formatter

I have done everything as told in the problem description and i am getting the correct answers as expected but still errors are show error on line 10 and line 39.The errors are
FAIL: test_arrangement (test_module.UnitTests)
FAIL: test_solutions (test_module.UnitTests)
i referred the test_module.py file too and i was getting the output specified in it but still the errors are shown.I am sure that my code is producing the correct output.Will the errors prevent me from getting a certificate

Your code so far

 def arithmetic_arranger(problems,answer=False):
  count=len(problems)
  elements=list()
  leftoperand=list()
  operator=list()
  rightoperand=list()
  lenleftoperand=list()
  lenrightoperand=list()
  out=list()
  results=list()
  resultslen=list()
  if count>5:
    prob="Error: Too many problems."
    print(prob)
    return prob
  else:
    for x in problems:
        endl=x.find(" ")
        lno=x[0:endl]
        lenlno=len(lno)

        if lenlno>4:
            probl="Error: Numbers cannot be more than four digits."
            print(probl)
            return probl
        else:
            lenleftoperand.append(lenlno)
        rno=x[endl+3:]
        lenrno=len(rno)
        if lenrno>4:

            probl="Error: Numbers cannot be more than four digits."
            print(probl)
            return probl
        else:
            lenrightoperand.append(lenrno)
        op=x[endl+1]

        if op!="+"and op!="-":
            probo="Error: Operator must be '+' or '-'."
            print(probo)
            return probo

        try:
            leftoperand.append(int(lno))
            operator.append(x[endl+1])
            rightoperand.append(int(rno))
        except:
            prob1="Error: Numbers must only contain digits."
            print(prob1)
            return prob1
    if answer==True:
        l=0
        i=0
        while l < count:
            maximum=max(lenleftoperand[i],lenrightoperand[i])
            i=i+1
            out.append(maximum+2)
            l=l+1
        p=0
        r=0
        while p < count:
            miss=out[r]-lenleftoperand[r]
            for k in range(miss):
                print(" ",end="")
            print(leftoperand[r],end="")
            print("    ",end="")
            r=r+1
            p=p+1
        print("",end="\n")
        q=0
        w=0
        while q < count:
            miss=out[w]-lenrightoperand[w]-1
            print(operator[w],end="")
            for k in range(miss):
                print(" ",end="")
            print(rightoperand[w],end="")
            print("    ",end="")
            w=w+1
            q=q+1
        print("",end="\n")
        g=0
        h=0
        while g < count:
            for k in range(out[h]):
                print("-",end="")
            print("    ",end="")
            g=g+1
            h=h+1
        print("",end="\n")
        l=0
        i=0
        while l < count:
            if operator[i]=='+':
                sum1=leftoperand[i]+rightoperand[i]

                results.append(sum1)
            else:
                if leftoperand>rightoperand:
                    diff=leftoperand[i]-rightoperand[i]
                    results.append(diff)
                else:
                    diff=leftoperand[i]-rightoperand[i]
                    sdiff=str(diff)
                    mdiff="-"+ sdiff


                    results.append(sdiff)

            l=l+1
            i=i+1
        for x in results:
            size=str(x)
            z=len(size)
            resultslen.append(z)
        a=0
        w=0
        while a < count:
            miss=out[w]-resultslen[w]

            for k in range(miss):
                print(" ",end="")
            print(results[w],end="")
            print("    ",end="")
            w=w+1
            a=a+1
        print("",end="\n")
    else:
        l=0
        i=0
        while l < count:
            maximum=max(lenleftoperand[i],lenrightoperand[i])
            i=i+1
            out.append(maximum+2)
            l=l+1
        p=0
        r=0
        while p < count:
            miss=out[r]-lenleftoperand[r]
            for k in range(miss):
                print(" ",end="")
            print(leftoperand[r],end="")
            r=r+1
            p=p+1
            if p==count:
                break
            print("    ",end="")
        print("")
        q=0
        w=0
        while q < count:
            miss=out[w]-lenrightoperand[w]-1
            print(operator[w],end="")
            for k in range(miss):
                print(" ",end="")
            print(rightoperand[w],end="")

            w=w+1
            q=q+1
            if q==count:
                break
            print("    ",end="")
        print("")
        g=0
        h=0
        while g < count:
            for k in range(out[h]):
                print("-",end="")
            g=g+1
            h=h+1
            if g==count:
                break
            print("    ",end="")
        print("")

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0.

Challenge: Arithmetic Formatter

Link to the challenge:

link to repl.it

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Hi nimithth.

I think you are printing an empty variable in one point:
image

Hope I can help you.

1 Like

Thank you sir for your feedback.I actually fixed the problem.The problem was as you stated

1 Like