I have a problem with replit when i run my code it gives me errors and fails but my output is right and i even downloaded the unit test file and tried to run it on my machine and it passed all tests.
My code
def arithmetic_arranger(lis, bool=False) :
import re
if len(lis) > 5:
print("Error: Too many problems.")
exit()
sumo = ""
str2 = ""
str3 = ""
space = ""
for i in lis :
erro = re.search("[a-z]+", i)
if erro != None :
print("Error: Numbers must only contain digits.")
exit()
num1,sign,num2 = i.split()
if len(num1) > 4 or len(num2) > 4 :
print("Error: Numbers cannot be more than four digits.")
exit()
if sign == "*" or sign == "/" :
print("Error: Operator must be '+' or '-'.")
exit()
if len(num1) == len(num2) :
str1 = sign + " " + num2
str3 += " " * (len(str1)-len(num1)) + num1 + " "
space += "-" * len(str1) + " "
str2 += str1 + " "
elif len(num2) > len(num1) :
str1 = sign + " "+ num2
str3 += " " * (len(str1)-len(num1)) + num1 + " "
space += "-" * len(str1) + " "
str2 += str1 + " "
else:
str1 = sign + " "*(len(num1)-len(num2)) + num2
str3 += " " * (len(str1)-len(num1)) + num1 + " "
space += "-" * len(str1) + " "
str2 += str1 + " "
if bool == True :
if sign == "+" :
i = str(int(num1)+int(num2))
sumo += " " * (len(str1)-len(i)) + i + " "
elif sign == "-" :
i = str(int(num1)-int(num2))
sumo += " " * (len(str1)-len(i)) + i + " "
print(str3)
print(str2)
print(space)
if bool == True :
print(sumo)
the console output
python main.py
32 3801 45 123
+ 698 - 2 + 43 + 49
----- ----- ---- ----
None
3 3801 45 123
+ 855 - 2 + 43 + 49
----- ----- ---- ----
FError: Operator must be '+' or '-'.
EError: Numbers must only contain digits.
E 32 1 45 123
- 698 - 3801 + 43 + 49
----- ------ ---- ----
-666 -3800 88 172
FError: Numbers cannot be more than four digits.
EError: Too many problems.
E
======================================================================
ERROR: test_incorrect_operator (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-arithmetic-formatter-4/test_module.py", line 22, in test_incorrect_operator
actual = arithmetic_arranger(["3 / 855", "3801 - 2", "45 + 43", "123 + 49"])
File "/home/runner/boilerplate-arithmetic-formatter-4/arithmetic_arranger.py", line 25, in arithmetic_arranger
exit()
File "/usr/lib/python3.8/_sitebuiltins.py", line 26, in __call__
raise SystemExit(code)
SystemExit: None
======================================================================
ERROR: test_only_digits (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-arithmetic-formatter-4/test_module.py", line 32, in test_only_digits
actual = arithmetic_arranger(["98 + 3g5", "3801 - 2", "45 + 43", "123 + 49"])
File "/home/runner/boilerplate-arithmetic-formatter-4/arithmetic_arranger.py", line 17, in arithmetic_arranger
exit()
File "/usr/lib/python3.8/_sitebuiltins.py", line 26, in __call__
raise SystemExit(code)
SystemExit: None
======================================================================
ERROR: test_too_many_digits (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-arithmetic-formatter-4/test_module.py", line 27, in test_too_many_digits
actual = arithmetic_arranger(["24 + 85215", "3801 - 2", "45 + 43", "123 + 49"])
File "/home/runner/boilerplate-arithmetic-formatter-4/arithmetic_arranger.py", line 22, in arithmetic_arranger
exit()
File "/usr/lib/python3.8/_sitebuiltins.py", line 26, in __call__
raise SystemExit(code)
SystemExit: None
======================================================================
ERROR: test_too_many_problems (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-arithmetic-formatter-4/test_module.py", line 17, in test_too_many_problems
actual = arithmetic_arranger(["44 + 815", "909 - 2", "45 + 43", "123 + 49", "888 + 40", "653 + 87"])
File "/home/runner/boilerplate-arithmetic-formatter-4/arithmetic_arranger.py", line 6, in arithmetic_arranger
exit()
File "/usr/lib/python3.8/_sitebuiltins.py", line 26, in __call__
raise SystemExit(code)
SystemExit: None
======================================================================
FAIL: test_arrangement (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-arithmetic-formatter-4/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: None != ' 3 3801 45 123\n+ 855 [56 chars]----' : Expected different 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/boilerplate-arithmetic-formatter-4/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 arithmetic problems and a second argument of `True`.')
AssertionError: None != ' 32 1 45 123\n- 698 [90 chars] 172' : Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with arithmetic problems and a second argument of `True`.
----------------------------------------------------------------------
Ran 6 tests in 0.006s
FAILED (failures=2, errors=4)