my code seems to work fine on command line but its failing fcc test on repl.it.
ive tried but i cant figure it out.
def arithmetic_arranger(problems, solved=True):
line1 = ''
line2 = ''
line3 = ''
line4 = ''
# To check for number of problems
if len(problems) > 5:
return "Error: Too many prolems"
for z, problem in enumerate(problems):
num1, op, num2 = problem.split()
#Test for operator
if op =='*' or op == '/':
return "Error: operator must be '+' or '-'"
#test for digits
if num1.isdigit() == False or num2.isdigit() == False:
return "Error: Numbers must only contain digits"
#test for lenght of Numbers
if len(num1) > 4 or len(num2) > 4:
return "rror: Numbers can not be more than four digits"
if op == '+':
result = int(num1) + int(num2)
elif op == '-':
result = int(num1) - int(num2)
#space setup
len_num1 = len(num1)
len_num2 = len(num2)
space = max(len_num1, len_num2) + 2
extra_space = ' '
#line arrange
line1 += num1.rjust(space)
line2 += op + num2.rjust(space -1)
line3 += "-" * space
line4 += str(result).rjust(space)
if z < len(problem) - 1:
line1 += extra_space
line2 += extra_space
line3 += extra_space
line4 += extra_space
if solved:
solution = line1 + '\n' + line2 + '\n' + line3 + '\n' + line4
else:
solution = line1 + '\n' + line2 + '\n' + line3
return solution
this is the link to the test https://repl.it/@seunlaww/SnivelingWateryArchives-1