FCC python assertion errors

I completed arithmetic formatter and time calculator both are working fine in the IDE however in replit are giving assertion errors in all test cases. very confused.

Please post your code and the error messages.

Hi thank you Jeremy for your reply, please find the codes and the errors below.

*Arithmetic formatter code:*

def arithmetic_arranger(problems, results=False):
  opp = '+'
  opn = '-'
  nprob = len(problems)
  tns = ''
  bc = ''
  dash = ''
  frslt = ''
  h = 0
  checker = True

  for error in problems:
    err = error.split()
    try:
      int(err[0])
      int(err[2])
    except:
      print("Error: Numbers must only contain digits.")
      checker = False
      break
    if len(err[0]) > 4 or len(err[2]) > 4:
      print("Error: Numbers cannot be more than four digits.")
      checker = False
      break
    if err[1] == opp or err[1] == opn:
      continue
    else:
      print("Error: Operator must be '+' or '-'.")
      checker = False
      break
  if checker:
    if nprob > 4:
      print("Error: Too many problems.")
    else:
      for problem in problems:
        crcs = problem.split()
        x = len(crcs[2])-len(crcs[0])
        y = len(crcs[0])-len(crcs[2])
    
        if x > 0:
          tns = tns+(2+x)*' '+crcs[0]+'    '
        else:
          tns = tns+2*' '+crcs[0]+'    '
    
        if y > 0:
          bc = bc+crcs[1]+(1+y)*' '+crcs[2]+'    '
        else:
          bc = bc+crcs[1]+' '+crcs[2]+'    '
    
        if len(crcs[0]) > len(crcs[2]):
          dash1 = (len(crcs[0])+2)*'-'
        elif len(crcs[0]) <  len(crcs[2]):
          dash1 = (len(crcs[2])+2)*'-'
        else:
          dash1 = (len(crcs[0])+2)*'-'
        dash = dash+dash1+'    '
    
        if crcs[1] == opp:
          rslt = int(crcs[0])+int(crcs[2])
        elif crcs[1] == opn:
          rslt = int(crcs[0])-int(crcs[2])
        trslt = str(rslt)
    
        if h == 0:
          z = len(dash1)-len(trslt)
        else:
          z = len(dash1)+4-len(trslt)
        frslt = frslt+z*' '+trslt
        h = h+1
        
  
  arranged_problems = print(tns.rstrip())
  arranged_problems = print(bc.rstrip())
  arranged_problems = print(dash.rstrip())
  if results:
    arranged_problems = print(frslt.rstrip())

  return arranged_problems

Console

 python3 main.py
   32      3801      45      123
+ 698    -    2    + 43    +  49
-----    ------    ----    -----
None
===================================================================== test session starts =====================================================================
platform linux -- Python 3.10.8, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /home/runner/boilerplate-arithmetic-formatter-2/venv/bin/python3
cachedir: .pytest_cache
rootdir: /home/runner/boilerplate-arithmetic-formatter-2
collected 10 items                                                                                                                                            

test_module.py::test_template[test_two_problems_arrangement1] FAILED                                                                                    [ 10%]
test_module.py::test_template[test_two_problems_arrangement2] FAILED                                                                                    [ 20%]
test_module.py::test_template[test_four_problems_arrangement] FAILED                                                                                    [ 30%]
test_module.py::test_template[test_five_problems_arrangement] FAILED                                                                                    [ 40%]
test_module.py::test_template[test_too_many_problems] FAILED                                                                                            [ 50%]
test_module.py::test_template[test_incorrect_operator] FAILED                                                                                           [ 60%]
test_module.py::test_template[test_too_many_digits] FAILED                                                                                              [ 70%]
test_module.py::test_template[test_only_digits] FAILED                                                                                                  [ 80%]
test_module.py::test_template[test_two_problems_with_solutions] FAILED                                                                                  [ 90%]
test_module.py::test_template[test_five_problems_with_solutions] FAILED                                                                                 [100%]

========================================================================== FAILURES ===========================================================================
________________________________________________________ test_template[test_two_problems_arrangement1] ________________________________________________________

arguments = [['3801 - 2', '123 + 49']], expected_output = '  3801      123\n-    2    +  49\n------    -----'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]
E       assert None == '  3801      123\n-    2    +  49\n------    -----'
E         +None
E         -'  3801      123\n-    2    +  49\n------    -----'

test_module.py:77: AssertionError
-------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------
  3801      123
-    2    +  49
------    -----
________________________________________________________ test_template[test_two_problems_arrangement2] ________________________________________________________

arguments = [['1 + 2', '1 - 9380']], expected_output = '  1         1\n+ 2    - 9380\n---    ------'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["1 + 2", "1 - 9380"]'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["1 + 2", "1 - 9380"]
E       assert None == '  1         1\n+ 2    - 9380\n---    ------'
E         +None
E         -'  1         1\n+ 2    - 9380\n---    ------'

test_module.py:77: AssertionError
-------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------
  1         1
+ 2    - 9380
---    ------
________________________________________________________ test_template[test_four_problems_arrangement] ________________________________________________________

arguments = [['3 + 855', '3801 - 2', '45 + 43', '123 + 49']]
expected_output = '    3      3801      45      123\n+ 855    -    2    + 43    +  49\n-----    ------    ----    -----'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]
E       assert None == ('    3      3801      45      123\n'\n '+ 855    -    2    + 43    +  49\n'\n '-----    ------    ----    -----')
E         +None
E         -'    3      3801      45      123\n+ 855    -    2    + 43    +  49\n-----    ------    ----    -----'

test_module.py:77: AssertionError
-------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------
    3      3801      45      123
+ 855    -    2    + 43    +  49
-----    ------    ----    -----
________________________________________________________ test_template[test_five_problems_arrangement] ________________________________________________________

arguments = [['11 + 4', '3801 - 2999', '1 + 2', '123 + 49', '1 - 9380']]
expected_output = '  11      3801      1      123         1\n+  4    - 2999    + 2    +  49    - 9380\n----    ------    ---    -----    ------'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]
E       assert None == ('  11      3801      1      123         1\n'\n '+  4    - 2999    + 2    +  49    - 9380\n'\n '----    ------    ---    -----    ------')
E         +None
E         -'  11      3801      1      123         1\n+  4    - 2999    + 2    +  49    - 9380\n----    ------    ---    -----    ------'

test_module.py:77: AssertionError
-------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------
Error: Too many problems.



____________________________________________________________ test_template[test_too_many_problems] ____________________________________________________________

arguments = [['44 + 815', '909 - 2', '45 + 43', '123 + 49', '888 + 40', '653 + 87']], expected_output = 'Error: Too many problems.'
fail_message = 'Expected calling "arithmetic_arranger()" with more than five problems to return "Error: Too many problems."'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected calling "arithmetic_arranger()" with more than five problems to return "Error: Too many problems."
E       assert None == 'Error: Too many problems.'
E         +None
E         -'Error: Too many problems.'

test_module.py:77: AssertionError
-------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------
Error: Too many problems.



___________________________________________________________ test_template[test_incorrect_operator] ____________________________________________________________

arguments = [['3 / 855', '3801 - 2', '45 + 43', '123 + 49']], expected_output = "Error: Operator must be '+' or '-'."
fail_message = 'Expected calling "arithmetic_arranger()" with a problem that uses the "/" operator to return "Error: Operator must be \'+\' or \'-\'."'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected calling "arithmetic_arranger()" with a problem that uses the "/" operator to return "Error: Operator must be '+' or '-'."
E       assert None == "Error: Operator must be '+' or '-'."
E         +None
E         -"Error: Operator must be '+' or '-'."

test_module.py:77: AssertionError
-------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------
Error: Operator must be '+' or '-'.



_____________________________________________________________ test_template[test_too_many_digits] _____________________________________________________________

arguments = [['24 + 85215', '3801 - 2', '45 + 43', '123 + 49']], expected_output = 'Error: Numbers cannot be more than four digits.'
fail_message = 'Expected calling "arithmetic_arranger()" with a problem that has a number over 4 digits long to return "Error: Numbers cannot be more than four digits."'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected calling "arithmetic_arranger()" with a problem that has a number over 4 digits long to return "Error: Numbers cannot be more than four digits."
E       assert None == 'Error: Numbers cannot be more than four digits.'
E         +None
E         -'Error: Numbers cannot be more than four digits.'

test_module.py:77: AssertionError
-------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------
Error: Numbers cannot be more than four digits.



_______________________________________________________________ test_template[test_only_digits] _______________________________________________________________

arguments = [['98 + 3g5', '3801 - 2', '45 + 43', '123 + 49']], expected_output = 'Error: Numbers must only contain digits.'
fail_message = 'Expected calling "arithmetic_arranger()" with a problem that contains a letter character in the number to return "Error: Numbers must only contain digits."'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected calling "arithmetic_arranger()" with a problem that contains a letter character in the number to return "Error: Numbers must only contain digits."
E       assert None == 'Error: Numbers must only contain digits.'
E         +None
E         -'Error: Numbers must only contain digits.'

test_module.py:77: AssertionError
-------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------
Error: Numbers must only contain digits.



_______________________________________________________ test_template[test_two_problems_with_solutions] _______________________________________________________

arguments = [['3 + 855', '988 + 40'], True], expected_output = '    3      988\n+ 855    +  40\n-----    -----\n  858     1028'
fail_message = 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with ["3 + 855", "988 + 40"] and a second argument of `True`.'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with ["3 + 855", "988 + 40"] and a second argument of `True`.
E       assert None == '    3      988\n+ 855    +  40\n-----    -----\n  858     1028'
E         +None
E         -'    3      988\n+ 855    +  40\n-----    -----\n  858     1028'

test_module.py:77: AssertionError
-------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------
    3      988
+ 855    +  40
-----    -----
  858     1028
______________________________________________________ test_template[test_five_problems_with_solutions] _______________________________________________________

arguments = [['32 - 698', '1 - 3801', '45 + 43', '123 + 49', '988 + 40'], True]
expected_output = '   32         1      45      123      988\n- 698    - 3801    + 43    +  49    +  40\n-----    ------    ----    -----    -----\n -666     -3800      88      172     1028'
fail_message = 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with five arithmetic problems and a second argument of `True`.'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with five arithmetic problems and a second argument of `True`.
E       assert None == ('   32         1      45      123      988\n'\n '- 698    - 3801    + 43    +  49    +  40\n'\n '-----    ------    ----    -----    -----\n'\n ' -666     -3800      88      172     1028')
E         +None
E         -'   32         1      45      123      988\n- 698    - 3801    + 43    +  49    +  40\n-----    ------    ----    -----    -----\n -666     -3800      88      172     1028'

test_module.py:77: AssertionError
-------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------
Error: Too many problems.




=================================================================== short test summary info ===================================================================
FAILED test_module.py::test_template[test_two_problems_arrangement1] - AssertionError: Expected different output when calling "arithmetic_arranger()" with [...
FAILED test_module.py::test_template[test_two_problems_arrangement2] - AssertionError: Expected different output when calling "arithmetic_arranger()" with [...
FAILED test_module.py::test_template[test_four_problems_arrangement] - AssertionError: Expected different output when calling "arithmetic_arranger()" with [...
FAILED test_module.py::test_template[test_five_problems_arrangement] - AssertionError: Expected different output when calling "arithmetic_arranger()" with [...
FAILED test_module.py::test_template[test_too_many_problems] - AssertionError: Expected calling "arithmetic_arranger()" with more than five problems to retu...
FAILED test_module.py::test_template[test_incorrect_operator] - AssertionError: Expected calling "arithmetic_arranger()" with a problem that uses the "/" op...
FAILED test_module.py::test_template[test_too_many_digits] - AssertionError: Expected calling "arithmetic_arranger()" with a problem that has a number over ...
FAILED test_module.py::test_template[test_only_digits] - AssertionError: Expected calling "arithmetic_arranger()" with a problem that contains a letter char...
FAILED test_module.py::test_template[test_two_problems_with_solutions] - AssertionError: Expected solutions to be correctly displayed in output when calling...
FAILED test_module.py::test_template[test_five_problems_with_solutions] - AssertionError: Expected solutions to be correctly displayed in output when callin...
===================================================================== 10 failed in 0.23s ======================================================================

> time calculator

def add_time(start, duration, day=False):
  before_miday = 'AM'
  after_miday = 'PM'
  n = 0
  week_day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
  comment = ''

  if day:
    s = 0
    for d in week_day:
      if d.lower() == day.lower():
        s = week_day.index(d)

  time_start = start.split()
  a = time_start[0]
  hrsmin_start = a.split(':')
  hrs_start = int(hrsmin_start[0])
  min_start = int(hrsmin_start[1])
  time_sys = time_start[1]

  if hrs_start != 12 and time_sys == after_miday:
    hrs_start += 12
  elif hrs_start == 12 and time_sys == before_miday:
    hrs_start -= 12

  start_time = hrs_start*60+min_start

  time_duration = duration.split()
  b = time_duration[0]
  hrsmin_duration = b.split(':')
  hrs_duration = int(hrsmin_duration[0])
  min_duration = int(hrsmin_duration[1])
  duration_time = hrs_duration*60+min_duration

  total_time = start_time+duration_time

  z = total_time/60
  total_hrs = total_time//60
  total_min = round((z-total_hrs)*60)
  if total_min < 10:
    total_min = '0'+str(total_min)
  if total_hrs >= 24:
    while total_hrs >=24:
      total_hrs -= 24
      n += 1
  if day:
    f = s+n
    if f >= 7:
      while f >=7:
        f = f-7
    d = week_day[f]

  if n == 1:
    comment = "(next day)"
  elif n > 1:
    comment = '('+str(n)+' days later)'

  if total_hrs > 12:
    total_hrs -= 12
    time_sys = after_miday
  elif total_hrs == 12:
    time_sys = after_miday
  elif total_hrs == 0:
    total_hrs += 12
    time_sys = before_miday
  else:
    time_sys = before_miday
  total_hrs = str(total_hrs)

  new_time = print(total_hrs+':'+str(total_min),time_sys,end='')
  if day:
    new_time = print(',',d,end='')
  new_time = print('',comment)
  
  return new_time

Console:

 python3 main.py
1:08 AM (next day)
3:07 PM 
F6:18 AM (20 days later)
F6:18 AM, Monday (20 days later)
F2:45 AM (next day)
F5:01 AM 
F12:05 PM 
F5:42 PM 
F5:42 PM, Monday 
F2:59 AM (next day)
F2:59 AM, Sunday (next day)
F12:04 AM (2 days later)
F12:04 AM, Friday (2 days later)
F
======================================================================
FAIL: test_different_period (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-time-calculator-1/test_module.py", line 15, in test_different_period
    self.assertEqual(actual, expected, 'Expected calling "add_time()" with "11:55 AM", "3:12" to return "3:07 PM"')
AssertionError: None != '3:07 PM' : Expected calling "add_time()" with "11:55 AM", "3:12" to return "3:07 PM"

======================================================================
FAIL: test_high_duration (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-time-calculator-1/test_module.py", line 40, in test_high_duration
    self.assertEqual(actual, expected, 'Expected calling "add_time()" with "8:16 PM", "466:02" to return "6:18 AM (20 days later)"')
AssertionError: None != '6:18 AM (20 days later)' : Expected calling "add_time()" with "8:16 PM", "466:02" to return "6:18 AM (20 days later)"

======================================================================
FAIL: test_high_duration_with_day (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-time-calculator-1/test_module.py", line 65, in test_high_duration_with_day
    self.assertEqual(actual, expected, 'Expected calling "add_time()" with "8:16 PM", "466:02", "tuesday" to return "6:18 AM, Monday (20 days later)"')
AssertionError: None != '6:18 AM, Monday (20 days later)' : Expected calling "add_time()" with "8:16 PM", "466:02", "tuesday" to return "6:18 AM, Monday (20 days later)"

======================================================================
FAIL: test_next_day (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-time-calculator-1/test_module.py", line 20, in test_next_day
    self.assertEqual(actual, expected, 'Expected time to end with "(next day)" when it is the next day.')
AssertionError: None != '2:45 AM (next day)' : Expected time to end with "(next day)" when it is the next day.

======================================================================
FAIL: test_no_change (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-time-calculator-1/test_module.py", line 45, in test_no_change
    self.assertEqual(actual, expected, 'Expected adding 0:00 to return initial time.')
AssertionError: None != '5:01 AM' : Expected adding 0:00 to return initial time.

======================================================================
FAIL: test_period_change_at_twelve (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-time-calculator-1/test_module.py", line 25, in test_period_change_at_twelve
    self.assertEqual(actual, expected, 'Expected period to change from AM to PM at 12:00')
AssertionError: None != '12:05 PM' : Expected period to change from AM to PM at 12:00

======================================================================
FAIL: test_same_period (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-time-calculator-1/test_module.py", line 10, in test_same_period
    self.assertEqual(actual, expected, 'Expected calling "add_time()" with "3:30 PM", "2:12" to return "5:42 PM"')
AssertionError: None != '5:42 PM' : Expected calling "add_time()" with "3:30 PM", "2:12" to return "5:42 PM"

======================================================================
FAIL: test_same_period_with_day (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-time-calculator-1/test_module.py", line 50, in test_same_period_with_day
    self.assertEqual(actual, expected, 'Expected calling "add_time()" with "3:30 PM", "2:12", "Monday" to return "5:42 PM, Monday"')
AssertionError: None != '5:42 PM, Monday' : Expected calling "add_time()" with "3:30 PM", "2:12", "Monday" to return "5:42 PM, Monday"

======================================================================
FAIL: test_twenty_four (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-time-calculator-1/test_module.py", line 30, in test_twenty_four
    self.assertEqual(actual, expected, 'Expected calling "add_time()" with "2:59 AM", "24:00" to return "2:59 AM"')
AssertionError: None != '2:59 AM (next day)' : Expected calling "add_time()" with "2:59 AM", "24:00" to return "2:59 AM"

======================================================================
FAIL: test_twenty_four_with_day (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-time-calculator-1/test_module.py", line 55, in test_twenty_four_with_day
    self.assertEqual(actual, expected, 'Expected calling "add_time()" with "2:59 AM", "24:00", "saturDay" to return "2:59 AM, Sunday (next day)"')
AssertionError: None != '2:59 AM, Sunday (next day)' : Expected calling "add_time()" with "2:59 AM", "24:00", "saturDay" to return "2:59 AM, Sunday (next day)"

======================================================================
FAIL: test_two_days_later (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-time-calculator-1/test_module.py", line 35, in test_two_days_later
    self.assertEqual(actual, expected, 'Expected calling "add_time()" with "11:59 PM", "24:05" to return "12:04 AM (2 days later)"')
AssertionError: None != '12:04 AM (2 days later)' : Expected calling "add_time()" with "11:59 PM", "24:05" to return "12:04 AM (2 days later)"

======================================================================
FAIL: test_two_days_later_with_day (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-time-calculator-1/test_module.py", line 60, in test_two_days_later_with_day
    self.assertEqual(actual, expected, 'Expected calling "add_time()" with "11:59 PM", "24:05", "Wednesday" to return "12:04 AM, Friday (2 days later)"')
AssertionError: None != '12:04 AM, Friday (2 days later)' : Expected calling "add_time()" with "11:59 PM", "24:05", "Wednesday" to return "12:04 AM, Friday (2 days later)"

----------------------------------------------------------------------
Ran 12 tests in 0.007s

FAILED (failures=12)

There is a lot there. Lets do one thing at a time.

The instructions want you to return the error message instead of printing it.

arithmetic formatter:

Hi Jeremy I changed the code and it worked however 2 failed

code

def arithmetic_arranger(problems, results=False):
  opp = '+'
  opn = '-'
  nprob = len(problems)
  tns = ''
  bc = ''
  dash = ''
  frslt = ''
  h = 0
  checker = True
  arranged_problems = ''

  for error in problems:
    err = error.split()
    try:
      int(err[0])
      int(err[2])
    except:
      arranged_problems = "Error: Numbers must only contain digits."
      return arranged_problems
      checker = False
      break

    if len(err[0]) > 4 or len(err[2]) > 4:
      arranged_problems = "Error: Numbers cannot be more than four digits."
      return arranged_problems
      checker = False
      break
    if err[1] == opp or err[1] == opn:
      continue
    else:
      arranged_problems = "Error: Operator must be '+' or '-'."
      return arranged_problems
      checker = False
      break
  if checker:
    if nprob > 4:
      arranged_problems = "Error: Too many problems."
      return arranged_problems
    else:
      for problem in problems:
        crcs = problem.split()
        x = len(crcs[2]) - len(crcs[0])
        y = len(crcs[0]) - len(crcs[2])

        if x > 0:
          tns = tns + (2 + x) * ' ' + crcs[0] + '    '
        else:
          tns = tns + 2 * ' ' + crcs[0] + '    '

        if y > 0:
          bc = bc + crcs[1] + (1 + y) * ' ' + crcs[2] + '    '
        else:
          bc = bc + crcs[1] + ' ' + crcs[2] + '    '

        if len(crcs[0]) > len(crcs[2]):
          dash1 = (len(crcs[0]) + 2) * '-'
        elif len(crcs[0]) < len(crcs[2]):
          dash1 = (len(crcs[2]) + 2) * '-'
        else:
          dash1 = (len(crcs[0]) + 2) * '-'
        dash = dash + dash1 + '    '

        if crcs[1] == opp:
          rslt = int(crcs[0]) + int(crcs[2])
        elif crcs[1] == opn:
          rslt = int(crcs[0]) - int(crcs[2])
        trslt = str(rslt)

        if h == 0:
          z = len(dash1) - len(trslt)
        else:
          z = len(dash1) + 4 - len(trslt)
        frslt = frslt + z * ' ' + trslt
        h = h + 1

  if results:
    arranged_problems = '\n'.join((tns.rstrip(), bc.rstrip(), dash.rstrip(), frslt.rstrip()))

  else:
    arranged_problems = '\n'.join((tns.rstrip(), bc.rstrip(), dash.rstrip()))

  return arranged_problems

Console

 python3 main.py
   32      3801      45      123
+ 698    -    2    + 43    +  49
-----    ------    ----    -----
===================================================================== test session starts =====================================================================
platform linux -- Python 3.10.8, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /home/runner/boilerplate-arithmetic-formatter-2/venv/bin/python3
cachedir: .pytest_cache
rootdir: /home/runner/boilerplate-arithmetic-formatter-2
collected 10 items                                                                                                                                            

test_module.py::test_template[test_two_problems_arrangement1] PASSED                                                                                    [ 10%]
test_module.py::test_template[test_two_problems_arrangement2] PASSED                                                                                    [ 20%]
test_module.py::test_template[test_four_problems_arrangement] PASSED                                                                                    [ 30%]
test_module.py::test_template[test_five_problems_arrangement] FAILED                                                                                    [ 40%]
test_module.py::test_template[test_too_many_problems] PASSED                                                                                            [ 50%]
test_module.py::test_template[test_incorrect_operator] PASSED                                                                                           [ 60%]
test_module.py::test_template[test_too_many_digits] PASSED                                                                                              [ 70%]
test_module.py::test_template[test_only_digits] PASSED                                                                                                  [ 80%]
test_module.py::test_template[test_two_problems_with_solutions] PASSED                                                                                  [ 90%]
test_module.py::test_template[test_five_problems_with_solutions] FAILED                                                                                 [100%]

========================================================================== FAILURES ===========================================================================
________________________________________________________ test_template[test_five_problems_arrangement] ________________________________________________________

arguments = [['11 + 4', '3801 - 2999', '1 + 2', '123 + 49', '1 - 9380']]
expected_output = '  11      3801      1      123         1\n+  4    - 2999    + 2    +  49    - 9380\n----    ------    ---    -----    ------'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]
E       assert 'Error: Too many problems.' == ('  11      3801      1      123         1\n'\n '+  4    - 2999    + 2    +  49    - 9380\n'\n '----    ------    ---    -----    ------')
E         + Error: Too many problems.
E         -   11      3801      1      123         1
E         - +  4    - 2999    + 2    +  49    - 9380
E         - ----    ------    ---    -----    ------

test_module.py:77: AssertionError
______________________________________________________ test_template[test_five_problems_with_solutions] _______________________________________________________

arguments = [['32 - 698', '1 - 3801', '45 + 43', '123 + 49', '988 + 40'], True]
expected_output = '   32         1      45      123      988\n- 698    - 3801    + 43    +  49    +  40\n-----    ------    ----    -----    -----\n -666     -3800      88      172     1028'
fail_message = 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with five arithmetic problems and a second argument of `True`.'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with five arithmetic problems and a second argument of `True`.
E       assert 'Error: Too many problems.' == ('   32         1      45      123      988\n'\n '- 698    - 3801    + 43    +  49    +  40\n'\n '-----    ------    ----    -----    -----\n'\n ' -666     -3800      88      172     1028')
E         + Error: Too many problems.
E         -    32         1      45      123      988
E         - - 698    - 3801    + 43    +  49    +  40
E         - -----    ------    ----    -----    -----
E         -  -666     -3800      88      172     1028

test_module.py:77: AssertionError
=================================================================== short test summary info ===================================================================
FAILED test_module.py::test_template[test_five_problems_arrangement] - AssertionError: Expected different output when calling "arithmetic_arranger()" with [...
FAILED test_module.py::test_template[test_five_problems_with_solutions] - AssertionError: Expected solutions to be correctly displayed in output when callin...
================================================================= 2 failed, 8 passed in 0.30s =================================================================

hi Randel
yes you are right, sorry.

ok i will change it to problem.

What’s the maximum number of problems? It isn’t 4!

I changed error to problem

:scream: ohh hhhh sorry man

thanks man its working

I’ve completed the time calculator, thanks a lot for your help. :facepunch:

1 Like

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