Scientific Computing with Python Projects - Arithmetic Formatter

I´ve got an error while i was trying to run the script:

File "/home/runner/boilerplate-arithmetic-formatter-1/", line 11, in <module>
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/", line 143, in main
    config = _prepareconfig(args, plugins)
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/", line 318, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/pluggy/", line 265, in __call__
    return self._hookexec(, self.get_hookimpls(), kwargs, firstresult)
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/pluggy/", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/pluggy/", line 55, in _multicall
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/", line 100, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/pluggy/", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/pluggy/", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/", line 1003, in pytest_cmdline_parse
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/", line 1283, in parse
    self._preparse(args, addopts=addopts)
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/", line 1157, in _preparse
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/", line 1073, in _initini
    ns, unknown_args = self._parser.parse_known_and_unknown_args(
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/", line 155, in parse_known_and_unknown_args
    optparser = self._getparser()
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/", line 113, in _getparser
    optparser = MyOptionParser(self, self.extra_info, prog=self.prog)
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/", line 381, in __init__
TypeError: ArgumentParser.__init__() got an unexpected keyword argument 'allow_abbrev'
exit status 1

Your code so far
This is my code:

def arithmetic_arranger(problems, show_result=False):
  if len(problems) > 5:
    return "Error: Too many problems."
  first_terms = []
  second_terms = []
  results = []
  maximums = []
  for problem in problems:
    first = problem.split()[0]
    second = " ".join(problem.split()[1:])
    if "+" not in second or "-" not in second:
      return "Error: Operator must be '+' or '-'."
    if not (first.isdigit() and problem.split()[-1].isdigit()):
      return "Error: Numbers must only contain digits."
    if not (len(first) < 5 and len(problem.split()[-1]) < 5):
      return "Error: Numbers cannot be more than four digits."
    if len(first) < len(second):
      first = first.rjust(len(second))
      max = len(second)
      second = second.rjust(len(first))
      max = len(first)
    maximums.append("-" * max)
    if show_result:
  output = "    ".join(first_terms) + "\n"
  output += "    ".join(second_terms) + "\n"
  output += "    ".join(maximums) + "\n"
  if show_result:
    output += "    ".join(results)
  return output

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Scientific Computing with Python Projects - Arithmetic Formatter

Link to the challenge:

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

Can you post a link to the replit (place the link inside angled brackets like <link>)

Thank You! I´ve found the issue. The way to fix it was uninstalling the argparse library using pip. I did that and then I could run the tests properly. Anyway, here i left the link with my code: and the solution for the issue i´ve posted:

1 Like