def arithmetic_arranger(test_lst, solve = False):
# Test so that number of problems is not more than 5
if(len(test_lst) > 5):
return 'Error: Too many problems.'
else:
pass
# Variables to store the full strings (the ones to return)
top = ''
den = ''
line = ''
ans = ''
for x in test_lst:
temp = x.split()
first = temp[0]
operand = temp[1]
second = temp[2]
temp_ans = ''
if (operand not in ['-', '+']):
return "Error: Operator must be '+' or '-'."
else:
pass
if (len(first) > 4 or len(second) > 4):
return "Error: Numbers cannot be more than four digits."
else:
pass
if (solve and (operand == '+' or operand == '-')):
if(operand == '+'):
temp_ans = str(int(first)+int(second))
else:
temp_ans = str(int(first)-int(second))
elif(solve):
return "Error: Operator must be '+' or '-'."
else:
pass
if (not first.isnumeric() or not second.isnumeric()):
return "Error: Numbers must only contain digits."
else:
pass
# Put together string and adjust spaces
line_len = max(len(first), len(second)) + 2
first = first.rjust(line_len)
second = second.rjust(line_len-1)
temp_ans = temp_ans.rjust(line_len)
if (x != test_lst[-1]):
line += '-'*line_len + ' '
ans += temp_ans + ' '
top += first + ' '
den += operand + second + ' '
else:
line += '-'*line_len
ans += temp_ans
top += first
den += operand + second
arrenged_problems = top+'\n'+den+'\n'+line+'\n'+ans+'\n'
return arrenged_problems

Works fine when running in terminal on computer. But test complains over 2 failures.

1:
Expected solutions to be correctly displayed in output when calling “arithmetic_arranger()” with arithemetic problems and a second argument of True

2:
Expected different output when calling “arithmetic_arranger()” with [“3 + 855”, “3801 - 2”, “45 + 43”, “123 + 49”]

here it’s shown the differential result: the lines starting with - are from your output and the lines starting with + are what the output should be, the lines starting with ? show the difference between the two

As I read it, the test wants to have a total of 6 lines at the final problem, but the total length of the largest of the 2 strings that makes up the output is 5. How could this be?