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?