I’m having troubles to complete the challenge of Arithmetic Arranger.
When I test my code in “main.py” I get a lot of mistakes that are not when I parse the values used in “test_module.py”.
def arithmetic_arranger(problems,condition=False):
import re
# SEPARO TEXTO POR ESPACIO Y VUELVO A GUARDAR
count = -1
for i in problems:
count = count + 1
problems[count] = re.split("\\s+", problems[count])
count = -1
arranged_problems = list()
l = list()
# SEPARO NUMERO SUPERIOR, INFERIOR Y TOTAL, ADEMAS PRUEBO LONGITUDES Y SI TIENEN SIGNOS QUE NO FUNCIONAN
if len(problems)>4:
print("Error: Too many problems.")
exit()
for i in problems:
count = count + 1
l = []
for j in i:
if (len(j) > 4):
print("Error: Numbers cannot be more than four digits.")
exit()
if j == "+":
pass
elif j == "-":
pass
elif j =="/":
print("Error: Operator must be '+' or '-'.")
exit()
elif j =="*":
print("Error: Operator must be '+' or '-'.")
exit()
if "+" in i:
try:
l.append(int(problems[count][0]))
l.append(int(problems[count][2]))
l.append(int(problems[count][0]) + int(problems[count][2]))
arranged_problems.append(l)
except:
print("Error: Numbers must only contain digits.")
exit()
elif "-" in i:
try:
l.append(int(problems[count][0]))
l.append((-1) * int(problems[count][2]))
l.append(int(problems[count][0]) - int(problems[count][2]))
arranged_problems.append(l)
except:
print("Error: Numbers must only contain digits.")
exit()
l2 = list()
lf = list()
for row in zip(*arranged_problems):
list(row)
for j in row:
lf.append(str(j))
last = list()
for i in range(len(problems)):
lista = list()
lista.append(lf[int(i)])
lista.append(lf[int(i + len(problems))])
lista.append(int(len(problems)) * "-")
lista.append(lf[int(i + 2 * len(problems))])
last.append(lista)
if condition is True:
for row in zip(*last):
print('{:>5}{:>10}{:>8}{:>9}'.format(*row))
return arranged_problems
He means that your image does not show the error that you are getting. It will be easier to tell you what is wrong if you post the error message along with your code.
Please provide a link to your project on replit, so we can actually see the error-message.
Nobody here can read your code and then just calculate the test-outputs in their head
Hm… ok so try reading the error messages, they are not that hard once you get the basics.
First line is just telling you that it is showing you previously steps (literally saying it’s just tracing back from the error)
Second is the file where the error occured
Third is the line in the file.
Fourth is the actual error-type and error-message.
The line before said it is first looking at your actual output and then the expected output.
Your output: [[3, 855, 858], [3801, -2, 3799], [45, 43[17 chars]172]]
Expected output: ' 3 3801 45 123\n+ 855 [56 chars]----'
Soooo you are returning a list of lists, each corresponding to a problem (first is the first calculation, second is the second one…). But that is not at all what you were supposed to do. You are supposed to arrange those problems into a text-string, as is described in the task.