Arithmetical formatter :S

def arithmetic_arranger(problems, solution=False):
  #1) len(problems) > 5: "Error: Too many problems."
  #2) Just + and -.
  #3) Only digits
  #4) No more than four digits
  #5) four spaces between each problem
  #checking the len of problems
  if len(problems) > 5:
    return "Error: Too many problems."
  first = ''
  second = ''
  lines = ''
  string = ''
  final = ''

  for problem in problems:
    one = problem.split(' ')[0]
    op = problem.split(' ')[1]
    two = problem.split(' ')[2]
    #operations checking
    if op not in ['+', '-']:
      return "Error: Operator must be '+' or '-'."
    #checking if there is any letters and if len of numbers are more than 4
    if one.isnumeric() == False or two.isnumeric() == False:
      if len(one) > 4 or len(two)>4:
        return "Error: Numbers must only contain digits."
      return "Error: Numbers cannot be more than four digits."

    #finding the result
    res = ''
    if op == '+':
      res = str(int(one) + int(two))
    elif op == '-':
      res = str(int(one) - int(two))

    #setting up the spaces
    length = max(len(one), len(two))+2
    ups = str(one).rjust(length)
    downs = op + str(two).rjust(length-1)
    smx = str(res).rjust(length)

    #setting the dashes
    line = ''
    for a in range(length):
      line += '-'

    #removing white spaces
    if problem != problems[-1]:
      lines += line + "    "
      first += ups + "    "
      second += downs + "    "
      final += smx + "    "
    else:
      lines += line 
      first += ups
      second += downs 
      final += smx 
      
  if solution:
    string = ups + '\n' + downs + '\n' + lines
  else:
    string = ups + '\n' + downs + '\n' + lines + '\n' + final
  return string

I don’t get where I’m getting wrong … I 've just pass so far two tests so far

Looks pretty backwards to me.

it will not work properly if is inside the ‘for problem in problems loops’’, isn’t it?

I didn’t say to put it in the loop, I said it’s backwards. Check again what “solution” is supposed to do :wink:

I still don’t get it :SSSS, with a couple of adaptions I’m failing 6 tests now.
and when I try to run this on Sublime text or VSCode it’s just show the last element of the list and not the other elements

If solution is true, you should show the final line - you are doing the exact opposite.

oh damn… what a mistake! :slight_smile: