def arithmetic_arranger(problems, solution=False):
#1) len(problems) > 5: "Error: Too many problems."
#2) Just + and -.
#3) Only digits
#4) No more than four digits
#5) four spaces between each problem
#checking the len of problems
if len(problems) > 5:
return "Error: Too many problems."
first = ''
second = ''
lines = ''
string = ''
final = ''
for problem in problems:
one = problem.split(' ')[0]
op = problem.split(' ')[1]
two = problem.split(' ')[2]
#operations checking
if op not in ['+', '-']:
return "Error: Operator must be '+' or '-'."
#checking if there is any letters and if len of numbers are more than 4
if one.isnumeric() == False or two.isnumeric() == False:
if len(one) > 4 or len(two)>4:
return "Error: Numbers must only contain digits."
return "Error: Numbers cannot be more than four digits."
#finding the result
res = ''
if op == '+':
res = str(int(one) + int(two))
elif op == '-':
res = str(int(one) - int(two))
#setting up the spaces
length = max(len(one), len(two))+2
ups = str(one).rjust(length)
downs = op + str(two).rjust(length-1)
smx = str(res).rjust(length)
#setting the dashes
line = ''
for a in range(length):
line += '-'
#removing white spaces
if problem != problems[-1]:
lines += line + " "
first += ups + " "
second += downs + " "
final += smx + " "
else:
lines += line
first += ups
second += downs
final += smx
if solution:
string = ups + '\n' + downs + '\n' + lines
else:
string = ups + '\n' + downs + '\n' + lines + '\n' + final
return string
I don’t get where I’m getting wrong … I 've just pass so far two tests so far