Scientific Computing with Python Projects - Arithmetic Formatter

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

File "/home/runner/boilerplate-arithmetic-formatter-1/main.py", line 11, in <module>
    main(['-vv'])
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 143, in main
    config = _prepareconfig(args, plugins)
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 318, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/pluggy/_manager.py", 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/_callers.py", line 55, in _multicall
    gen.send(outcome)
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/helpconfig.py", 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/_result.py", 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/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1003, in pytest_cmdline_parse
    self.parse(args)
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1283, in parse
    self._preparse(args, addopts=addopts)
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1157, in _preparse
    self._initini(args)
  File "/home/runner/boilerplate-arithmetic-formatter-1/venv/lib/python3.10/site-packages/_pytest/config/__init__.py", 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/argparsing.py", 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/argparsing.py", 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/argparsing.py", line 381, in __init__
    argparse.ArgumentParser.__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)
    else:
      second = second.rjust(len(first))
      max = len(first)
    first_terms.append(first)
    second_terms.append(second)
    maximums.append("-" * max)
    if show_result:
      results.append(str(eval(problem)).rjust(max))
  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/108.0.0.0 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: https://replit.com/@AlejandroHassan/boilerplate-arithmetic-formatter-1#arithmetic_arranger.py and the solution for the issue i´ve posted: https://stackoverflow.com/questions/55619099/django-admin-typeerror-init-got-an-unexpected-keyword-argument-allow-abb

1 Like

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