# Arithmetic Formatter : Help me get sideways Edition

Hi, I’m new and this is what I’ve got so far:

``````def arithmetic_arranger(problems):

operators = ('+', '-')
arranged_problems = []
if(len(problems) >= 6):
return "Error: Too many problems."
elif(len(problems) == 0) :
return "Error: No problems given."
else:
for eq in problems :
x,y,z = eq.split(' ')
top_op = []
bot_op = []
if y not in operators :
return "Error: Operator must be '+' or '-'."
elif len(str(x)) >= 5 or len(str(z)) >= 5 :
return "Error: Numbers cannot be more than four digits."
elif x.isdigit() == False or z.isdigit() == False :
return "Error: Numbers must only be digits."
else :
#print(x,y,z)
top = f"{x:>6}   "
bot = f"{y:<}{z:>5}   "
#vert_eq = f"{x:>6}    \n{y:<}{z:>5}    \n------    "
print(top + '\n' + bot + '\n' + '------')

return arranged_problems

arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])
``````

So I’ve been playing with the formatting and I can get the equations to be formatted correctly individually ( I did this in two ways), but I’ve been a little lost on how to get them to be printed horizontally.

Should I be making lists for each formatted value? Should I just store the values in lists and then format the items of the lists? Can ‘arranged_problems’ be a list of all three lines, already formatted? Should I even be using lists?

Update:

``````def arithmetic_arranger(problems):

operators = ('+', '-')
if(len(problems) >= 6):
return "Error: Too many problems."
elif(len(problems) == 0) :
return "Error: No problems given."
else:
top_op = str()
bot_op = str()
for eq in problems :
x,y,z = eq.split(' ')
if y not in operators :
return "Error: Operator must be '+' or '-'."
elif len(str(x)) >= 5 or len(str(z)) >= 5 :
return "Error: Numbers cannot be more than four digits."
elif x.isdigit() == False or z.isdigit() == False :
return "Error: Numbers must only be digits."
else :
top_op += str(f"{x:>6}   ")
bot_op += str(f"{y:<}") + str(f"{z:>5}   ")
dashes = '------   '
arranged_problems = top_op + '\n' + bot_op + '\n' + (dashes * len(problems))

return print(arranged_problems)

arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])
``````
I haven't figured out how/if I could make a list of the complete equations horizontally, so I just made each line a string and added in the formatted values from the loop.

I’m still not sure if this is the right direction, but the output is at least starting to look like the desired output from the project.

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