# HELP! Arithmetic Formatter's output has random F letters on it

Tell us what’s happening:
The output on replit’s console has F letters before every Error print, one before one of the operations, and another one just before the output end. I have no idea why, since my code has no F on it. Because of that I am still getting all the failures.
I also get a “None” on the output, but I don’t know if that’s normal or not.
If someone could shine a light on this, I would be very grateful, thank you.

``````import re

def arithmetic_arranger(problems, sums=False):
#defining variables
n1 = ""
n2 = ""
op = ""
sum = ""
top_list = []
middle_list = []
slashes = []
sums = []
string = ""

#first obligatory error checking
if len(problems) > 5 :
print('Error: Too many problems.')

else :

#splitting the problem for easier manipulation
for problem in problems:
n1 = problem.split()[0]
n2 = problem.split()[2]
op = problem.split()[1]

#obligatory error checking
if op == '/' or op == '*':
print ("Error: Operator must be '+' or '-'.")

elif re.search('\D', n1) or re.search('\D', n2) :
print('Error: Numbers must only contain digits.')

elif len(n1) >= 5 or len(n2) >= 5 :
print('Error: Numbers cannot be more than four digits.')

else :
#doing the operation for sum=True statements
if op == "+" :
sum = str(int(n1) + int(n2))

elif op == "-" :
sum = str(int(n1) - int(n2))

#figuring out the numbers of slashes and spaces needed.
spaces_n1 = ""
spaces_n2 = ""

if len(n1) >= len(n2) :
slash = '-' * (len(n1) + 2)
spaces_n1 = ' ' * (len(slash) - len(n1))
spaces_n2 = ' ' * ((len(slash) - len(n2)) - 2)
slashes.extend(slash + "    ")

elif len(n2) > len(n1) :
slash = '-' * (len(n2) + 2)
spaces_n1 = ' ' * (len(slash) - len(n1))
spaces_n2 = ' ' * ((len(slash) - len(n2)) - 2)
slashes.extend(slash + "    ")

spaces_sum = ' ' * (len(slash) - len(sum))

#appending the parts needed to the lists for printing
top_list.extend([spaces_n1, n1, "    "])
middle_list.extend([op, " ", spaces_n2, n2, "    "])
sums.extend([spaces_sum, sum + "    "])

#turning the lists into strings to concatenate in the print statement.
top_string = ''.join(top_list)
top_string = top_string.rstrip()
middle_string = ''.join(middle_list)
middle_string = middle_string.rstrip()
slashes_string = ''.join(slashes)
slashes_string = slashes_string.rstrip()
sums_string = ''.join(sums)
sums_string = sums_string.rstrip()

#check if sums=True for the appropriate print statement
if sums :
string = (top_string + "\n" + middle_string + "\n" + slashes_string + "\n" + sums_string + "\n")
print(string)
else :
string = (top_string + "\n" + middle_string + "\n" + slashes_string + "\n")
print(string)

``````

Output

``````   32
+ 698
-----
730

32      3801
+ 698    -    2
-----    ------
730      3799

32      3801      45
+ 698    -    2    + 43
-----    ------    ----
730      3799      88

32      3801      45      123
+ 698    -    2    + 43    +  49
-----    ------    ----    -----
730      3799      88      172

None
3
+ 855
-----
858

3      3801
+ 855    -    2
-----    ------
858      3799

3      3801      45
+ 855    -    2    + 43
-----    ------    ----
858      3799      88

3      3801      45      123
+ 855    -    2    + 43    +  49
-----    ------    ----    -----
858      3799      88      172

FError: Operator must be '+' or '-'.
3801
-    2
------
3799

3801      45
-    2    + 43
------    ----
3799      88

3801      45      123
-    2    + 43    +  49
------    ----    -----
3799      88      172

FError: Numbers must only contain digits.
3801
-    2
------
3799

3801      45
-    2    + 43
------    ----
3799      88

3801      45      123
-    2    + 43    +  49
------    ----    -----
3799      88      172

F   32
- 698
-----
-666

32         1
- 698    - 3801
-----    ------
-666     -3800

32         1      45
- 698    - 3801    + 43
-----    ------    ----
-666     -3800      88

32         1      45      123
- 698    - 3801    + 43    +  49
-----    ------    ----    -----
-666     -3800      88      172

FError: Numbers cannot be more than four digits.
3801
-    2
------
3799

3801      45
-    2    + 43
------    ----
3799      88

3801      45      123
-    2    + 43    +  49
------    ----    -----
3799      88      172

FError: Too many problems.
F
``````

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

Challenge: Arithmetic Formatter

The Fs indicate that you have test suite failures.

You are not actually `return`ing this variable, so you are `return`ing the default value of `None`. (`print` is not the same thing as `return`).

Also, I wouldn’t name any variable `string`. It is best not to name variables after types(integer, int, string, bool, etc), even in Python, which lets you use pretty bad variable names.

I tried changing the print statements to return but I’m still getting error on the test_arrangement and test_sollutions and still getting a none. Now I have no idea what did wrong again, and everything is vertical, but it’s at least less error messages?

``````   32
+ 698
-----
730
None
3
+ 855
-----
858
F..   32
- 698
-----
-666
F..
``````

It looks like you are returning too early now. You should only return outside of your loop over all problems.

Thank you again!
I’m still getting an error on test_arrangement. It appears to be expecting a different first operation than the one on the output? It seems to expected 3 + 855 instead of 32 + 698, or am I reading it wrong? Am I somehow giving out the wrong operation?how???

``````   32      3801      45      123
+ 698    -    2    + 43    +  49
-----    ------    ----    -----
730      3799      88      172
F.....
======================================================================
FAIL: test_arrangement (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-arithmetic-formatter-6/test_module.py", line 10, in test_arrangement
self.assertEqual(actual, expected, 'Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]')
AssertionError: '    [68 chars]-    ------    ----    -----\n  858      3799      88      172' != '    [68 chars]-    ------    ----    -----'
3      3801      45      123
+ 855    -    2    + 43    +  49
- -----    ------    ----    -----
?                                 -
+ -----    ------    ----    ------   858      3799      88      172 : Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]
``````

You seem to be adding the solutions row when it wasn’t requested.

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