I’m trying to debug the arithmetic arranger and I’m not understanding why I’m getting so many error codes
def arithmetic_arranger(problems, solved = True):
line1 = ''
line2 = ''
line3 = ''
line4 = ''
# number of problem checker
if len(problems) > 5:
return "Error, too many problems."
for z, problems in enumerate(problems):
num1, operators, num2 = problems.split()
#allowed operators
operators = ['+' , '-']
if operators is not operators:
return "Error, incorrect operators."
#number checker
if num1.isdigit() == False or num2.isdigit() == False:
return "Error, please use numbers."
#length of number checker
if len(num1) > 4 or len(num2) > 4:
return "Error, numbers must be less than four digits."
if operators == '+':
return int(num1) + int(num2)
if operators == "-":
return int(num1) - int(num2)
#spacing
num1_len = len(num1)
num2_len = len(num2)
space = max(num1_len, num2_len) + 2
more_space = ' '
#line arrangement
line1 += num1.rjust(space)
line2 += operators and num2.rjust(space - 1)
line3 += "-" * space
line4 += str().rjust(space)
if z < len(problems) - 1:
line1 += more_space
line2 += more_space
line3 += more_space
line4 += more_space
if solved:
solution = line1 + '\n' + line2 + '\n' + line3 + '\n' + line4
else:
solution = line1 + '\n' + line2 + '\n' + line3
return solution
Using google chrome
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
.
Challenge: Arithmetic Formatter
Link to the challenge: