Good wishes everybody.
Below is the error message i am getting when i execute my code here. I am getting proper output while the code is executed in the VS Code. Will be grateful for your help. After the error message i have pasted the code of arithemtic_arranger function.
Error message :
32 3801 45 123
+ 698 - 2 + 43 + 49
----- ------ ---- -----
F..F..
======================================================================
FAIL: test_arrangement (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-arithmetic-formatter-2/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: ' 3 3801 45 123 \n + 855[69 chars] \n ' != ' 3 3801 45 123\n+ 855 - [51 chars]----'
- 3 3801 45 123
? - ----
+ 3 3801 45 123
- + 855 - 2 + 43 + 49
? - ----
+ + 855 - 2 + 43 + 49
- ----- ------ ---- -----
? - -----
+ ----- ------ ---- ------ : 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-2/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: ' 32 1 45 123 \n - 69[106 chars] ' != ' 32 1 45 123\n- 698 -[86 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.018s
Arithmetic Arranger function code :
def arithmetic_arranger(problems, to_display = False):
# validating list
# 1. list must have maximum 5 sums.
# 2. Operators must '+' or '-'.
# 3. Numbers must only contains digit.
# 4. Number cannot be more than four digits.
Operator1 = 0 # for saving first operator
Operator2 = 0 # for saving second operator
Operand = ''
# 1. list must have maximum 5 sums.
if len(problems) > 5:
# print('Too many problems.')
return 'Error: Too many problems.'
for sum in problems :
# seperating operators and operands from the sum
sum = sum.split()
Operand = sum[1]
# 2. Operators must '+' or '-'.
if Operand != '+' and Operand != '-':
# print(Operand)
# print("Error: Operator must be '+' or '-'.")
return "Error: Operator must be '+' or '-'."
# 3. Numbers must only contains digits.
try:
Operator1 = int(sum[0])
Operator2 = int(sum[2])
except ValueError:
# print("Error: Numbers must only contain digits.")
return "Error: Numbers must only contain digits."
# 4. Number cannot be more than four digits.
if len(sum[0]) > 4 or len(sum[2]) > 4:
# print("Error: Numbers cannot be more than four digits.")
return "Error: Numbers cannot be more than four digits."
# Calculating results and displaying.
op1_list = []
op2_list = []
op3_list = []
for sum in problems:
sum = sum.split()
op1_list.append(sum[0] )
op2_list.append(sum[1])
op3_list.append(sum[2])
# Printing first operand horizontally
counter = 0
first_line = ''
while counter < len(op1_list) :
# print(op1_list[counter].rjust((len(op3_list[counter]) + 2) if len(op3_list[counter]) > len(op1_list[counter]) else len(op1_list[counter]) + 2) , end = " " * 4)
first_line = first_line + str(op1_list[counter].rjust((len(op3_list[counter]) + 2) if len(op3_list[counter]) > len(op1_list[counter]) else len(op1_list[counter]) + 2)) + " " * 4
counter = counter + 1
# print("Printing first line")
# print(first_line)
# print(' ')
# Printing operator and second operand horizontally.
counter = 0
second_line = ''
while counter < len(op2_list) :
# print(op2_list[counter] , end = " ")
# print(op3_list[counter].rjust((len(op3_list[counter])) if len(op3_list[counter]) > len(op1_list[counter]) else len(op1_list[counter])) , end = " " * 4)
second_line = second_line + str(op2_list[counter]) + " " + str(op3_list[counter].rjust((len(op3_list[counter])) if len(op3_list[counter]) > len(op1_list[counter]) else len(op1_list[counter]))) + " " * 4
counter = counter + 1
# print(" ")
# print("printing both lines ")
# print(first_line + '\n'+ second_line)
# Printing "--" between result and operand / operators.
counter = 0
third_line = ''
while counter < len(op3_list) :
# print('-' * (len(op3_list[counter]) + 2 if len(op3_list[counter]) > len(op1_list[counter]) else len(op1_list[counter]) + 2) , end = " " * 4)
third_line = third_line + '-' * (len(op3_list[counter]) + 2 if len(op3_list[counter]) > len(op1_list[counter]) else len(op1_list[counter]) + 2) + " " * 4
counter = counter + 1
# print("")
# print("printing three lines ")
# print(first_line + '\n'+ second_line + '\n' + third_line)
# Printing results
counter = 0
fourth_line = " "
while counter < len(op3_list) :
result = 0
if to_display == True:
if op2_list[counter] == '-' :
result = int(op1_list[counter]) - int(op3_list[counter])
elif op2_list[counter] == '+':
result = int(op1_list[counter]) + int(op3_list[counter])
# print(str(result).rjust((len(op3_list[counter]) + 2) if len(op3_list[counter]) > len(op1_list[counter]) else len(op1_list[counter]) + 2) , end = " " * 4 )
fourth_line = fourth_line + str(result).rjust((len(op3_list[counter]) + 2) if len(op3_list[counter]) > len(op1_list[counter]) else len(op1_list[counter]) + 2) + " " * 4
counter = counter + 1
return " " + first_line + '\n'+ " "+ second_line + '\n' +" "+ third_line + '\n' + fourth_line