# Arithmetic_arranger_submission

Hello everybody,
I worked on the arithmetic arranger project, I tried on many examples and it works fine but I don’t know why doesn’t pass the unit tests, here is my code:

``````def arithmetic_arranger(problems, res=False):

if len(problems)>5 :
print("Error : Too many problems.")
quit() ;
op1=[]
op2=[]
pl=[]
maxlen=[]
st1=''
st2=''
st3=''
st4=''
for oper in problems :
oper.rstrip()
oper.lstrip()
l=oper.split()
#print(l[1]=="+")
if l[1]!="+":

if l[1]!="-" :
print("Error: Operator must be '+' or '-'.")
quit()

try :
x1=int(l[0])
#print(x1)
x2=int(l[2])
#print(x2)
except :
print("Error: Numbers must only contain digits")
quit()

if len(l[0])>4 or len(l[2])>4 :
print("Error: Numbers cannot be more than four digits.")
quit()

#maxlen=max([len(l[0]), len(l[2])])+2
op1.append(l[0])
op2.append(l[2])
pl.append(l[1])

maxlen.append(max([len(l[0]), len(l[2])])+2)

for i in range(len(problems)) :
nbsp1=maxlen[i]-len(op1[i])
nbsp2=maxlen[i]-len(op2[i])
st1=st1+nbsp1*" "+op1[i]+4*" "
#print(st1)
st2=st2+pl[i]+" "+(nbsp2-2)*" "+op2[i]+4*" "
#print(st2)
st3=st3+maxlen[i]*"-"+4*" "
#print(st3)

if res==True :
if pl[i]=="+" :
ress=int(op1[i])+int(op2[i])
#print(ress)

elif pl[i]=="-" :
ress=int(op1[i])-int(op2[i])

ress1=str(ress)
#print(ress1)
nbsp3=maxlen[i]-len(ress1)
st4=st4+nbsp3*" "+ress1+4*" "
#print(st4)

#print(st1)
#print(st2)
#print(st3)
#print(st4)
if res==True :

resultat=st1+"\n"+st2+"\n"+st3+"\n"+st4
#print(resultat)

else :
resultat=st1+"\n"+st2+"\n"+st3

return resultat
``````

I would appreciate any help or indication. Thank you ^^

Thanks!

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 (’).

1 Like

You need to always return strings.

1 Like

Thank you @jwilkins.oboe

Thank you @JeremyLT I wasn’t aware about it, now it passes 2 tests out of 10

It would be a lot easier for me to debug if you provide the link to your repl.

Did you fix this one too?

And this one?

You’re probably appending superfluous spaces to the end of your lines.

Yes you are right @JeremyLT I am adding superfluous spaces at the end of my lines, I will try to fix it, thank you for very much ^^

1 Like

Thanks to you @JeremyLT , I passed all the unit test. Have a great day ^^

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.