# Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project

### Tell us what’s happening:

Hello everyone,
I’m encountering an issue with a testing platform I’m using to evaluate a code I’ve developed. I’ve written a function that seems to be working correctly, but the platform is marking some tests as incorrect, even when I believe my code is doing what’s expected of it.

``````def arithmetic_arranger(problems, show_answers=False):

for indice, problem in enumerate(problems, start=0):
return print('Error: Too many problems.')
sumando1 = ''
sumando2 = ''
linea = ''
tamaño = 0
for char in problem:
if char != ' ':
if char.isnumeric():
sumando1 += char
if len(sumando1) > 4:
return print('Error: Numbers cannot be more than four digits.')
else:
break
if char.isnumeric():
sumando2 = char + sumando2
if len(sumando2) > 4:
return print('Error: Numbers cannot be more than four digits.')
else:
break

else:
else:
return print("Error: Operator must be '+' or '-'.")
else:
return print('Error: Numbers must only contain digits.')

tamaño = len(sumando1) if len(sumando1) > len(sumando2) else len(sumando2)
for i in range (tamaño+2):
if len(sumando1) != tamaño+2:
sumando1 = ' ' + sumando1
if len(sumando2) != tamaño+1:
sumando2 = ' ' + sumando2

for j in range (tamaño+2):
linea += '_'

#0        #1        #2       #3       #4

else:

else:

else:

else:

arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])
print ('\n')
arithmetic_arranger(["32 + 8", "1 - 3801", "9999 + 9999", "523 - 49"], True)
print ('\n')
arithmetic_arranger(["3801 - 2", "123 + 49"])
print ('\n')
arithmetic_arranger(["1 + 2", "1 - 9380"])
print ('\n')
arithmetic_arranger(["3 + 855", "3801 - 2", "45 + 43", "123 + 49"])
print ('\n')
arithmetic_arranger(["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"])
print ('\n')
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36`

### Challenge Information:

Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project

Please format your code properly when you post it, it’s extremely important for languages like Python that rely on indentation

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

which function? what’s the correct behaviour? what platform, what tests, wrong how?
learning to explain your code is a critical skill

There is a more verbose version of the tests results in the browser console, at a cursory glance many of the tests are receiving `None`:
`AssertionError: None !=`

You should check that your function is returning the correct value

Hola josevalmorem

Tu codigo contiene estas lineas:

``````for j in range (tamaño+2):
linea += '_'
``````

En lugar de guiones bajos deben ser guiones medios.

``````  25      25(aqui hay espacios que no deben estar)
+ 15    - 15
----    ----
40      10
``````

Por ultimo devuelves los resultados con `print`, modifique un poco tu codigo y cambinado lo que te mencione antes y devolviendo los resultados con ` return` algunas pruebas ya pasan.

``````return (guardado['variable0'][0] + '\n'+ guardado['variable0'][1] + '\n'+ guardado['variable0'][3] + '\n' + guardado['variable0'][4] + '\n')
``````

saludos

1 Like