What's the problem. I keep getting an Error

import re

def arithmetic_arranger(problems, solve = False):

  if(len(problems) > 5):
    return "Error: Too many problems"

    first = ""
    second = ""
    lines = ""
    sumx = ""
    string = ""
    for problem in problems:
      if(re.search("[^\s0-9.+-]", problem)):
        if(re.search("[/]", problem) or re.search("[*]", problem)):
          return "Error: Operator must be '+' or '-'."
        return "Error: Number must only contain digits."

      firstNumber = problem.split(" ")[0]
      operator = problem.split(" ")[1]
      secondNumber = problem.split(" ")[2]

      if(len(firstNumber) >= 5 or len(secondNumber)>= 5):
        return "Error: Number cannot be more than four digits."

      sum = ""
      if(operator == "+"):
        sum = str(int(firstNumber) + int(secondNumber))
      elif(operator == '-'):
        sum = str(int(firstNumber) - int(secondNumber))

      lenght = max(len(firstNumber), len(secondNumber)) + 2
      top = str(firstNumber).rjust(lenght)
      bottom = operator + str(secondNumber).rjust(lenght - 1)
      line = ""
      res = str(sum).rjust(lenght)
      for s in range (lenght):
        line += "-"

      if problem != problems[-1]:
        first += top + '    '
        second += bottom + '    '
        lines += line
        sumx += res
      else:
        first += top
        second += bottom
        lines += line
        sumx += res

    if solve:
      string = first + "\n" + second + "\n" + lines + "\n" + sumx
    else:
      string = first + "\n" + second + "\n" + lines 
      return string

What error are you getting?

i dont know why i cant run that code. It say that have error at line 10 than i try to move the code to make sure what the error, than it still say the error at line 10 but the position at line 10 code is already move to other line such as line 11 or 9.

what error are you getting?


I’ve edited your post 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 (’).