Tell us what’s happening:
I can get result for each test for “Build and Arithmetic Formatter Project” and result looks correct on Console view; however when I click on box "Run the Tests(Ctrl+Enter)), all fails and console doesn’t show any particular error
Your code so far
def arithmetic_arranger(problems, show_answers = False):
sumN = None
result = ''
if len(problems) > 5:
return (print('Error: Too many problems.'))
num1L = [i.split()[0] for i in problems]
signL = [i.split()[1] for i in problems]
num2L = [i.split()[2] for i in problems]
line1 = num1L[0].rjust(((max(len(num1L[0]), len(num2L[0]))))+2)
line2 = signL[0] + ' ' + num2L[0].rjust(max(len(num1L[0]), len(num2L[0])))
line3 = '--' + ('-' * max(len(num2L[0]), len(num1L[0]))) + ' '
for i in range(len(num1L)):
if len(num1L[i]) > 4 or len(num2L[i]) > 4:
return (print ('Error: Numbers cannot be more than four digits.' ))
elif num1L[i].isdigit() == False or num2L[i].isdigit() == False:
return (print('Error: Numbers must only contain digits.'))
elif signL[i] != '+' and signL[i] != '-':
retturn (print("Error: Operator must be '+' or '-'."))
if show_answers:
try:
if signL[0] == '+':
sumN = int(num1L[0])+int(num2L[0])
elif signL[0] == '-':
sumN = int(num1L[0])- int(num2L[0])
suml = str(sumN).rjust(len(line3)-4) + ' '
except:
return (print("Exception happened in calculation sum"))
for i in range(1, len(num1L)):
line1 += ' ' + num1L[i].rjust(max(len(num1L[i]), len(num2L[i])))
line2 += ' ' + signL[i].rjust(0) + ' ' + num2L[i].rjust(max(len(num1L[i]), len(num2L[i])))
line3 += '--' + ('-' * max(len(num2L[i]), len(num1L[i])))+' '
line3L = line3.split()
#print(line3,'\n', line3L)
if show_answers:
if signL[i] == '+':
sumN = int(num1L[i])+int(num2L[i])
else:
sumN = int(num1L[i])- int(num2L[i])
suml += str(sumN).rjust(len(line3L[-1]))+' '
sumL = suml.rstrip()
if show_answers:
result = line1+'\n'+line2+'\n'+line3.rstrip()+'\n'+sumL+'.'
return result
else:
result = line1+'\n'+line2+'\n'+line3.rstrip()+'.'
return result
#print(f'\n{arithmetic_arranger(["32 - 698", "1 - 3801", "45 + 43", "123 + 49", "988 + 40"], True)}')
print('\n')
print(repr(arithmetic_arranger(["32 - 698", "1 - 3801", "45 + 43", "123 + 49", "988 + 40"], True)))