i just finished the arithmetic arranger project of scientific computing with python project .
Every rule (test condition) was working fine on my editor but when i put the code of repl.in it thew two errors which i cannot understand.
this is my code
import operator
def con_check(a):
try:
a = int(a)
return True
except:
return False
def arithmetic_arranger(problems, con = False):
arranged_problems = ""
dict ={"+": operator.add,"-": operator.sub}
first = [*range(len(problems))]
second = [*range(len(problems))]
sign = [*range(len(problems))]
x = 0
for i in problems:
first[x], sign[x], second[x] = i.split()
if len(str(first[x])) > 4 or len(str(second[x])) > 4:
return "Error: Numbers cannot be more than four digits."
elif x > 4:
return "Error: Too many problems."
elif not sign[x] in dict:
print(sign[x])
return "Error: Operator must be '+' or '-'."
elif not con_check(first[x]) or not con_check(second[x]):
return "Error: Numbers must only contain digits."
x+=1
# first line
for i in range(len(problems)):
arranged_problems += str(" "*(len(str(max(int(first[i]), int(second[i])))) - len(str(first[i])) + 2 ) + first[i] + " ")
arranged_problems += str("\n")
#second line
for i in range(len(problems)):
arranged_problems += str(sign[i] + " " * (len(str(max(int(first[i]), int(second[i])) )) - len(second[i]) +1) + second[i] +" ")
arranged_problems += str("\n")
#Third line
for i in range(len(problems)):
arranged_problems += str("--" + "-" * (len(str(max(int(first[i]), int(second[i]))))) +" ")
arranged_problems += str("\n")
if con :
for i in range(len(problems)):
arranged_problems += str(" " * (len(str(max(int(first[i]), int(second[i])))) - len(str(dict[sign[i]](int(first[i]), int(second[i])))) + 2) + str(dict[sign[i]](int(first[i]), int(second[i]))) + " ")
return arranged_problems
And this is these are the two errors repl.in is throwing
..F..
=================================================
=====================
FAIL: test_arrangement (test_module.UnitTests)
-------------------------------------------------
---------------------
Traceback (most recent call last):
File "/home/runner/fcc-arithmetic-arranger/test
_module.py", line 10, in test_arrangement
self.assertEqual(actual, expected, 'Expected
different output when calling "arithmetic_arrange
r()" with ["3 + 855", "3801 - 2", "45 + 43", "123
+ 49"]')
AssertionError: ' [23 chars] 123 \n+ 855
- 2 + 43 + 49 [37 chars] \n' != '
[23 chars] 123\n+ 855 - 2 + 43 +
49\n-----[23 chars]----'
- 3 3801 45 123
? ----
+ 3 3801 45 123
- + 855 - 2 + 43 + 49
? ----
+ + 855 - 2 + 43 + 49
- ----- ------ ---- -----
? -----
+ ----- ------ ---- ----- : Expected dif
ferent output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]
======================================================================
FAIL: test_solutions (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/fcc-arithmetic-arranger/test_module.py", line 39, in test_solutions
self.assertEqual(actual, expected, 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with arithemetic problems and a second argument of `True`.')
AssertionError: ' 3[23 chars] 123 \n- 698 - 3801 + 43 + 49 [73 chars] ' != ' 3[23 chars] 123\n- 698 - 3801 + 43 + 49\n-----[57 chars] 172'
- 32 1 45 123
? ----
+ 32 1 45 123
- - 698 - 3801 + 43 + 49
? ----
+ - 698 - 3801 + 43 + 49
- ----- ------ ---- -----
? ----
+ ----- ------ ---- -----
- -666 -3800 88 172 ? ----
+ -666 -3800 88 172 : Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with arithemetic problems and a second argument of `True`.
----------------------------------------------------------------------
Ran 6 tests in 0.005s
FAILED (failures=2)
Thanks to help in advance!!