Tell us what’s happening:
My code passes 4 out of six tests, but when I see the output of the test it doesn’t pass, it seems that the outputs are equal, so it should pass. Am I missing something?
Your code so far
def arithmetic_arranger(*problems):
import re
if len(problems[0]) > 5:
arranged_problems = "Error: Too many problems."
return arranged_problems
else:
stringUp = ""
stringDown = ""
ralla = ""
stringResult = ""
for cadauno in problems[0]:
stringtmp = cadauno.split()
# Valida que los operadores sean "+" o "-"
if re.search('[a-zA-Z]', cadauno):
# Busca si hay letras en el arreglo, pues solo debe haber números.
arranged_problems = "Error: Numbers must only contain digits."
return arranged_problems
if (stringtmp[1] != '+') and (stringtmp[1] != '-'):
arranged_problems = "Error: Operator must be '+' or '-'."
return arranged_problems
else:
if len(stringtmp[0]) > 4 or len(stringtmp[2]) > 4:
# Valida que no sean mayores de 4 digitos
return "Error: Numbers cannot be more than four digits."
else:
ancho = max(len(stringtmp[0]), len(stringtmp[2])) + 2
stringUp = stringUp + stringtmp[0].rjust(ancho) + ' '
stringDown = stringDown + stringtmp[1] + stringtmp[2].rjust(ancho - 1) + ' '
ralla = ralla + ("_" * ancho) + ' '
if len(problems) > 1: # Valida si viene un segundo parámetro.
# >>>>>>>>>>>>>>> SUMAR EN LA TERCERA LINEA
if stringtmp[1] == '+':
stringResult = stringResult + str(int(stringtmp[0]) + int(stringtmp[2])).rjust(ancho) + ' '
else:
stringResult = stringResult + str(int(stringtmp[0]) - int(stringtmp[2])).rjust(ancho) + ' '
arranged_problems = stringUp.rstrip() + '\n' + stringDown.rstrip() + '\n' + ralla.rstrip()
if len(problems) > 1:
arranged_problems = arranged_problems + '\n' + stringResult.rstrip()
return arranged_problems
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36
.
Challenge: Arithmetic Formatter
Link to the challenge: