Scientific Computing with Python Projects - Arithmetic Formatter

Tell us what’s happening:

I’m stuck on the last two test questions, i dont know how to edit my code so it passes and i keep getting this error message

TypeError: arithmetic_arranger() takes 1 positional argument but 2 were given

Your code so far

def arithmetic_arranger(problems):
  # Checks to see if number of arguments is more than 5 
  if len(problems) > 5:
      return 'Error: Too many problems.'
  # Format for arithmetic
  arranged_sol = ''
  arranged_problems = ''
  top_line = ''
  middle_line = ''
  dash_line = ''

  for problem in problems:
      problem_list = problem.split()
      # Checks to see if arguments are digits 
      if not problem_list[0].isdigit() or not problem_list[2].isdigit():
          return 'Error: Numbers must only contain digits.'
      # Ensures that the length of the digits is not greater than 5
      if len(problem_list[0]) > 4 or len(problem_list[2]) > 4:
          return 'Error: Numbers cannot be more than four digits.'
      # Ensures that only plus and negative operators are used 
      if problem_list[1] not in ['+', '-']:
          return "Error: Operator must be '+' or '-'."

      # Calculates the width of the the arrenger format
      width = max(len(problem_list[0]), len(problem_list[2])) + 2
      # Takes the first index in list, adjust to the right based on the width
      top_line += problem_list[0].rjust(width) + '    '
      # Inserts operator to the left and adds second index
      middle_line += problem_list[1] + ' ' + problem_list[2].rjust(width - 2) + '    '
      # Calculates the number of dashes to add based on width
      dash_line += '-' * width + '    '

      # Calculates solution based on operator used
      if problem_list[1] == '+':
          solution = int(problem_list[0]) + int(problem_list[2])
          solution = int(problem_list[0]) - int(problem_list[2])

      # Adds the solution of the arguments below the dash line
      arranged_sol += '\n' + ' ' * (width - len(str(solution))) + str(solution) + '    '

  # Arranges the lines and dashes together
  arranged_problems = top_line.rstrip() + '\n' + middle_line.rstrip() + '\n' + dash_line.rstrip() + arranged_problems

  if True in problems:
    return arranged_sol
    return arranged_problems

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36 Edg/

Challenge Information:

Scientific Computing with Python Projects - Arithmetic Formatter

I would have to see the full code to really make sense for it. So if you could link the replit that would be lovely.

But the error is essentially saying that you defined the arithmetic_arranger() method with 1 arguement arithmetic_arranger(problems) . But somewhere it’s been called with 2 arguements. Unfortunately I don’t see the call to this function in your code so I can’t say for sure. Either it’s somewhere with 2 arguements, or it’s called on an object…

Oh if I remember correctly, it passed a boolean (somtimes) as a second argument that is True if they want the answers written too. So in your function definition you need to add something for the boolean that they (sometimes) provide.

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 (').