# Arithmetic Failing

I have no clue why this isnt working. it seems to work fine if I run the tests manually. but it fails on both arrangement and solutions. But if I manually print them they look exactly like they’re supposed to.

``````def arithmetic_arranger(problems, optional_answers = False):
first_numbers = []
operands = []
second_numbers = []
dashes = []
arranged_problems = ""

#checking for too many problems
if len(problems) > 5:
return "Error: Too many problems."

for problem in problems:
length = 0
current_problem = problem.split()

#checking for errors
if current_problem[0].isdigit() == False or current_problem[2].isdigit() == False:
return "Error: Numbers must only contain digits."

if current_problem[1] not in ('-', '+'):
return "Error: Operator must be '+' or '-'."

if len(current_problem[0]) > 4 or len(current_problem[2]) > 4:
return "Error: Numbers cannot be more than four digits."

#checking for the longest number
if len(current_problem[0]) >= len(current_problem[2]):
first_numbers.append(current_problem[0].rjust(len(current_problem[0])+2))
second_numbers.append(current_problem[2].rjust(len(current_problem[0])+2).replace(" ", current_problem[1],1))
dashes.append("".rjust(len(current_problem[0])+2,"-"))

if current_problem[1] == "-":
else:

else:
first_numbers.append(current_problem[0].rjust(len(current_problem[2])+2))
second_numbers.append(current_problem[2].rjust(len(current_problem[2])+2).replace(" ", current_problem[1],1))
dashes.append("".rjust(len(current_problem[2])+2,"-"))

if current_problem[1] == "-":
else:

for number in first_numbers:
arranged_problems += number + "    "
arranged_problems.strip()
arranged_problems += "\n"

for number in second_numbers:
arranged_problems += number + "    "
arranged_problems.strip()
arranged_problems += "\n"

for line in dashes:
arranged_problems += line + "    "
arranged_problems.strip()
arranged_problems += "\n"

arranged_problems += line + "    "
arranged_problems.strip()
arranged_problems += "\n"

return arranged_problems
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0`.

Challenge: Arithmetic Formatter

What errors are you getting exactly?

I’ve edited your post 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 (’).

thanks leahleen, I couldn’t figure out why part of my code was showing in a block and part of it wasn’t

no errors, just not passing the test. it probably has to do with how I formatted the string.
I posted a link. if you see what I did wrong please let me know!

if you run it you’ll see the manual tests. If you spot what’s wrong please let me know!

Take a look at this:
‘-’ = your output, ‘+’ = what it is supposed to be and ‘?’ are the differences.
Both Fails (you don’t want to call them ‘errors’ ) have the same problem,: too many spaces at the end of the lines. Make those disappear and you should be done!

``````-     3      3801      45      123
?                                 ----
+     3      3801      45      123
- + 855    -    2    + 43    +  49
?                                 ----
+ + 855    -    2    + 43    +  49
- -----    ------    ----    -----
?                                 -----
+ -----    ------    ----    ------
``````
``````-    32         1      45      123
?                                 ----
+    32         1      45      123
- - 698    - 3801    + 43    +  49
?                                 ----
+ - 698    - 3801    + 43    +  49
- -----    ------    ----    -----
?                                 ----
+ -----    ------    ----    -----
-  -666     -3800      88      172
?                                 -----
+  -666     -3800      88      172``````

thanks a lot! I’ll fix it later today.
about the errors thing. In my previous work fails were “doesnt pass test” and errors were “code doesnt even run”. Thought that was a universal thing. Guess I was wrong

Lol…well…if you had previous work in coding, you are definately my senior and your argumen does make sense, so Fail it is !

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.