# Scientific Computing with Python Projects - Arithmetic Formatter problem - not working

**URL:** <https://forum.freecodecamp.org/t/scientific-computing-with-python-projects-arithmetic-formatter-problem-not-working/415065>\
**Category:** General\
**Created:** [August 12, 2020, 11:05pm UTC](https://forum.freecodecamp.org/t/scientific-computing-with-python-projects-arithmetic-formatter-problem-not-working/415065 "2020-08-12T23:05:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![isaacfrith98](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/isaacfrith98/32/172880_2.png) [@isaacfrith98](https://forum.freecodecamp.org/u/isaacfrith98)\
**Post date:** [August 12, 2020, 11:05pm UTC](https://forum.freecodecamp.org/t/scientific-computing-with-python-projects-arithmetic-formatter-problem-not-working/415065/1 "2020-08-12T23:05:11Z")

</div>

def arithmetic\_arranger(problems, showAns = False):  
if len(problems)\>5:  
return “Error: Too many problems.”  
else:  
arranged\_problems =   
for i in problems:  
x = i.split()  
n1 = x[0]  
n2 = x[2]  
operand = x[1]

```
  if operand not in ["+", "-"]:
    return "Error: Operator must be '+' or '-'." 
  else:
    for digit in n1:
      if digit not in ["0","1","2","3","4","5","6","7","8","9"]:
        return "Error: Numbers must only contain digits." 
      else: 
        continue

    for digit in n2:
      if digit not in ["0","1","2","3","4","5","6","7","8","9"]:
        return "Error: Numbers must only contain digits." 
      else: 
        continue

    if len(n1)>4 or len(n2)>4:
      return "Error: Numbers cannot be more than four digits."
    else: 

        if operand == '+':
          answer = int(n1) + int(n2)
        else: 
          answer = int(n1) - int(n2)
        
        width = max(len(n1),len(n2)) +2
        topLine = str(n1.rjust(width))
        secondLine = str(operand + " " + n2)
        dashLine = str("-" * width)
        answerLine = str(answer).rjust(width)
        
        if showAns == True: 
          arranged_problems.append(topLine + "\n" + secondLine + "\n" + dashLine + "\n" + answerLine)
        else: 
          arranged_problems.append(topLine + "\n" + secondLine + "\n" + dashLine)

return arranged_problems
```

---

<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:43pm UTC](https://forum.freecodecamp.org/t/scientific-computing-with-python-projects-arithmetic-formatter-problem-not-working/415065/2 "2021-06-01T18:43:33Z")

</div>

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


