Tell us what’s happening:
so i began with this python for everybody course with abosolutely no knowledge about python. i started with this project some time ago but i keep getting this error and couldnt see what is wrong in this code.
Your code so far
def arithmetic_arranger(problems, con=False):
if len(problems) > 5:
return 'Error: Too many problems.'
for i in problems:
l = (i.split(' '))
num1 = l[0]
op = l[1]
num2 = l[2]
sums=num1+num2
if len(num1) > 4 or len(num2) > 4:
return 'Error: Numbers cannot be more than four digits.'
if not num1.isnumeric() or not num2.isnumeric():
return 'Error: Numbers must only contain digits.'
if op == '+' or op == '-':
length = max(len(num1), len(num2)) + 2
while (len(num1)<length):
num1=' '+num1
while (len(num2)<(length-1)):
num2=' '+num2
if not con:
arranged_problems = num1 + '\n' +op+ num2+'\n'+('-'*length)+'\n'+ sums + '\n'+('-'*length)
return arranged_problems
else:
arranged_problems = num1 + '\n' +op+ num2+ '\n'+('-'*length)
return arranged_problems
else:
return "Error: Operator must be '+' or '-'."
errors encountered
/ Starting Repl... 32
+ 698
-----
32698
-----
F..F..
======================================================================
FAIL: test_arrangement (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/yrwt8p0z24s/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\n+ 855\n-----\n3855\n-----' != ' 3 3801 45 123\n+ 855 - [50 chars]----'
+ 3 3801 45 123
+ + 855 - 2 + 43 + 49
+ ----- ------ ---- ------ 3
- + 855
- -----
- 3855
- ----- : 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/yrwt8p0z24s/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\n- 698\n-----' != ' 32 1 45 123\n- 698 - 3[84 chars] 172'
- 32
- - 698
- -----+ 32 1 45 123
+ - 698 - 3801 + 43 + 49
+ ----- ------ ---- -----
+ -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.002s
FAILED (failures=2)
Connection closed abruptly
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 OPR/71.0.3770.287
.
Challenge: Arithmetic Formatter
Link to the challenge: