Tell us what’s happening:
The tests for printing the arithmetic is wrong, and if you check the error message F12 you see 939 errors
python-test-evaluator.js:2 PythonError: Traceback (most recent call last):
File “/lib/python311.zip/_pyodide/_base.py”, line 468, in eval_code
.run(globals, locals)
^^^^^^^^^^^^^^^^^^^^
File “/lib/python311.zip/_pyodide/_base.py”, line 310, in run
coroutine = eval(self.code, globals, locals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “”, line 4, in <module
Your code so far
def arithmetic_arranger(problems, show_answers=False):
arrLen=len(problems)
tempArr=[]
problemSize=[]
firstOpArr=[]
secondOpArr=[]
resultArr=[]
lineArr=[]
lineChar='-'
outputStrFirst=''
outputStrSecond=''
outputStrResult=''
outputStrLine=''
problemSpace=' '
for i in problems:
tempArr=i.strip().split(' ')
if tempArr[1]!= "+" and tempArr[1]!= "-":
return "Error: Operator must be '+' or '-'."
if not tempArr[0].isdigit() or not tempArr[2].isdigit():
return "Error: Numbers must only contain digits."
if len(tempArr[0])>4 or len(tempArr[2])>4:
return 'Error: Numbers cannot be more than four digits.'
if arrLen>5:
return 'Error: Too many problems.'
for p in problems:
tempLen=0
tempArr=p.strip().split(' ')
if len(tempArr[0])>len(tempArr[2]):
tempLen=len(tempArr[0])+2
else:tempLen=len(tempArr[2])+2
problemSize.append(tempLen)
#print("string needed len:",problemSize)
for index,f in enumerate(problems):
tempArr=f.strip().split(' ')
tempString=tempArr[0].strip()
tempStringLen=len(tempString)
paddString=tempString.rjust(problemSize[index])
firstOpArr.append(paddString)
for index,s in enumerate(problems):
tempArr=s.strip().split(' ')
tempString=tempArr[2].strip()
tempStringLen=len(tempString)
paddString=tempString.rjust(problemSize[index]-2)
paddStringOp=f'{tempArr[1]} {paddString}'
secondOpArr.append(paddStringOp)
#print(secondOpArr)
for l in problemSize:
lineArr.append(lineChar*l)
if True:
for prn in range(len(firstOpArr)):
outputStrFirst+=firstOpArr[prn]+problemSpace
outputStrSecond+=secondOpArr[prn]+problemSpace
outputStrLine+=lineArr[prn]+problemSpace
outputStrResult+=str((eval(f'{firstOpArr[prn]}{secondOpArr[prn]}'))).rjust(problemSize[prn])+problemSpace
if not show_answers:
return f'{outputStrFirst}\n{outputStrSecond}\n{outputStrLine}'
else: return f'{outputStrFirst}\n{outputStrSecond}\n{outputStrLine}\n{outputStrResult}'
print(arithmetic_arranger(["3801 - 2", "123 + 49"]))
print(' 3801 123\n- 2 + 49\n------ -----')
print()
print(arithmetic_arranger(["1 + 2", "1 - 9380"]))
print(' 1 1\n+ 2 - 9380\n--- ------')
print()
print(arithmetic_arranger(["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]))
print(' 11 3801 1 123 1\n+ 4 - 2999 + 2 + 49 - 9380\n---- ------ --- ----- ------')
print()
print(arithmetic_arranger(["3 + 855", "988 + 40"], True))
print()
print(' 3 988\n+ 855 + 40\n----- -----\n 858 1028')
print()
print(arithmetic_arranger(["32 - 698", "1 - 3801", "45 + 43", "123 + 49", "988 + 40"], True))
print()
print(' 32 1 45 123 988\n- 698 - 3801 + 43 + 49 + 40\n----- ------ ---- ----- -----\n -666 -3800 88 172 1028')
print()
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Challenge Information:
Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project