# Arithmetic Formatter: Test Error

**URL:** <https://forum.freecodecamp.org/t/arithmetic-formatter-test-error/417799>\
**Category:** General\
**Created:** [August 28, 2020, 9:27pm UTC](https://forum.freecodecamp.org/t/arithmetic-formatter-test-error/417799 "2020-08-28T21:27:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukna](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lukna/32/144207_2.png) [@Lukna](https://forum.freecodecamp.org/u/Lukna)\
**Post date:** [August 28, 2020, 9:27pm UTC](https://forum.freecodecamp.org/t/arithmetic-formatter-test-error/417799/1 "2020-08-28T21:27:05Z")

</div>

I finished my code for the Arithmetic Formatter, and it works fine when I try out different examples, but repl.it keeps giving me Error messages and I don‘t get why.  
Here‘s my code:

```auto

def arithmetic_arranger(problems, x=False):
  if len(problems) > 5:
    print('Error: Too many problems.')
    quit()
  nums = ''
  dens = ''
  sums = ''
  dashs = ''
  for k in problems:
    op = k.split()[1]
    if op == '+' or op == '-': num,den = k.split(op)
    else:
      print("Error: Operator must be '+' or '-'.")
      quit()
    num = num.strip()
    den = den.strip()
    if len(num) > 4 or len(den) > 4:
      print('Error: Numbers cannot be more than four digits.')
      quit()
    length = max(len(num), len(den)) + 2
    if num.isnumeric() == False or den.isnumeric() == False:
      print('Error: Numbers must only contain digits.')
      quit()
    sump = int(num) + int(den)
    top = num.rjust(length)
    mid = op + ' ' + den.rjust(length - 2)
    nums += top + ' '
    dens += mid + ' '
    dashs += '-' * length + ' '
    sums += str(sump).rjust(length) + ' ' 
  if x == False:
    arranged_problems = nums + '\n' + dens + '\n' + dashs
  if x == True:
    arranged_problems = nums + '\n' + dens + '\n' + dashs + '\n' + sums
  return arranged_problems

```

Here‘s the link to the [repl.it](https://repl.it/@knaluk/fcc-arithmetic-arranger-1#arithmetic_arranger.py)

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![sanity](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sanity/32/378897_2.png) [@sanity](https://forum.freecodecamp.org/u/sanity)\
**Post date:** [August 29, 2020, 5:01am UTC](https://forum.freecodecamp.org/t/arithmetic-formatter-test-error/417799/2 "2020-08-29T05:01:40Z")

</div>

Take a closer look at the challenge specification, function shouldn’t print anything on it own. Instead it should return the specified string, this includes situation when there’s error encountered.

---

<div class="post-metadata">

**Author:** ![Lukna](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lukna/32/144207_2.png) [@Lukna](https://forum.freecodecamp.org/u/Lukna)\
**Post date:** [August 29, 2020, 1:05pm UTC](https://forum.freecodecamp.org/t/arithmetic-formatter-test-error/417799/3 "2020-08-29T13:05:21Z")

</div>

That‘s it, thank you!

---

<div class="post-metadata">

**Author:** ![nayankoshiya](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nayankoshiya/32/171954_2.png) [@nayankoshiya](https://forum.freecodecamp.org/u/nayankoshiya)\
**Post date:** [August 29, 2020, 3:14pm UTC](https://forum.freecodecamp.org/t/arithmetic-formatter-test-error/417799/4 "2020-08-29T15:14:02Z")

</div>

I do understand the solution provided by Lukna. I am incorporting it as a solution to my challenge and i acknowledge his work. However,I am not able to get whats wrong in the above solution. Why is it giving error?  
like what part is to be modified to get correct output.

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [August 29, 2020, 3:17pm UTC](https://forum.freecodecamp.org/t/arithmetic-formatter-test-error/417799/5 "2020-08-29T15:17:13Z")

</div>

It’s really best to create a new topic and provide a link to your code, as your issue is likely different than the original issue in this thread.

---

<div class="post-metadata">

**Author:** ![Lukna](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lukna/32/144207_2.png) [@Lukna](https://forum.freecodecamp.org/u/Lukna)\
**Post date:** [August 29, 2020, 6:13pm UTC](https://forum.freecodecamp.org/t/arithmetic-formatter-test-error/417799/6 "2020-08-29T18:13:58Z")

</div>

There are two more things wrong with the code, beside the print statements, as I later figured.

1. The sum variable only uses addition, it needs an if statement to also be able to solve subtraction.

Something like this:

```auto

if op == '+':
    sol = int(num) + int(den)
else:
    sol = int(num) - int(den)

```

(I changed the sum variable to sol)

1. The final variables in the end need to be r-stripped. (Variable.rstrip())

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:41pm UTC](https://forum.freecodecamp.org/t/arithmetic-formatter-test-error/417799/7 "2021-06-01T18:41:49Z")

</div>

Closed on June 1, 2021, 6:41pm UTC


