Tell us what’s happening:
No idea why I’m failing the test_arrangement and the test_solution tests. Everything looks good on my end but it seems like the test_module doesn’t like how I solved the programming challenge.
Your code so far
def arithmetic_arranger(problems, boolean = False):
charRemove = ['[',']',',','\'']
top = []
bottom = []
line = []
answer = []
for i in range(0,len(problems)):
x = problems[i].split()
if len(problems) > 5:
arranged_problems = 'Error: Too many problems.'
break
elif (len(x[0]) > 4) or (len(x[2]) > 4):
arranged_problems = 'Error: Numbers cannot be more than four digits.'
break
elif (not x[0].isnumeric() or not x[2].isnumeric()):
arranged_problems = 'Error: Numbers must only contain digits.'
break
elif ((x[1] != '+') and (x[1] != '-')):
arranged_problems = "Error: Operator must be '+' or '-'."
break
else:
top.append(x[0].rjust(5) + ' ' * 4)
bottom.append(x[1] + x[2].rjust(4) + ' ' * 4)
line.append('-----' + ' ' * 4)
if boolean == True:
answer.append(str(eval(problems[i])).rjust(5) + ' ' * 4)
v = str(top) + '\n' + str(bottom) + '\n' + str(line) + '\n' + str(answer)
for i in charRemove:
v = v.replace(i,'')
arranged_problems = v
return arranged_problems
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0
.
Challenge: Arithmetic Formatter
Link to the challenge: