# Need Help with Alignments in Arethmatic Arranger

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

num1 = []
num2 = []
oper = []
dash = []
ans = []
spaces = []

#number of equation check
if len(problems) >5 :
return("Error: Too many problems.")

for v in  problems:

fnum = v.split()[0]
num1.append(fnum)
op = v.split()[1]
oper.append(op)
lnum = v.split()[2]
num2.append(lnum)
len_1 = len(fnum)
len_2 = len(lnum)
d1 = max(len_1,len_2)+2
spaces.append(d1)
da = d1 * "-"
dash.append(da)

#Error Checkers:
if not fnum.isdigit() or not lnum.isdigit():
return('Error: Numbers must only contain digits.')
if op == '+':
total = int(fnum) + int(lnum)
ans.append(total)
elif op == '-':
total = int(fnum) - int(lnum)
ans.append(total)
else:
return("Error: Operator must be '+' or '-'.")
#check for digits

#check for digit length
if len(fnum) > 4 or len(lnum) > 4:
return('Error: Numbers cannot be more than four digits.')

l1 = []
l2 = []
d_ = []
ans_ = []
for (fl,o,ll,ds,sol,s) in zip(num1,oper,num2,dash,ans,spaces):
line_1 = str(fl).rjust(s) + (4 * " ")
l1.append(line_1)
line_2 = o + ll.rjust(s-1) + (4 * " ")
l2.append(line_2)
line_3 = ds + (4*' ')
d_.append(line_3)
line_4 = str(sol).rjust(s)+ (4*' ')
ans_.append(line_4)

a=''.join(l1)
b=''.join(l2)
c=''.join(d_)
g=''.join(ans_)

arithmetic_arranger= f"""{a}'\n'{b}'\n'{c}'\n'{g}"""

return arithmetic_arranger

``````

the output am getting looks like this

For starters, you need an extra space at the start of the first line so the 1s column lines up.

thank you for the response ive added a space to line_1

``````line_1 = ' ' + str(fl).rjust(s) + (4 * " ")

``````

and this is my output.

that’s why I posted it in the forum, no matter how I try to adjust it’s never right

Sorry if I was supposed to post the Replit link, I am new to coding and new to the ecosystem.
If you can kindly provide a verbose explanation as to why this is happening as well as a general feedback on my code, I will be forever grateful.

Thank you for the feedback. I have done the adjustments you suggested but to no avail

So I have tried something I removed the f string and decided to try it without the format is sent back perfectly aligned now, and it’s driving me crazy but thats for another day.
The test are still failing though

Thank you, after restarting Replit everything seems fine now.
thank you for the support

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