Arithmetic Formatter - Please Help!

Hi! Why am I getting this error?

line 33
else :
SyntaxError: invalid syntax

My code so far:

def arithmetic_arranger(problems, *k):
  arranged_problems = ""
  (line1, line2, line3, line4) = ("", "", "", "")
  
  if len(problems) > 5 : 
    arranged_problems = "Error: Too many problems."
  else :
    for i in  range(len(problems)) :
      operation = problems[i].split()

      try:  
        operation[0] = int(operation[0])  # termo 1
        operation[2] = int(operation[2])  # termo 2
      except:
        arranged_problems = "Error: Numbers must only contain digits."
        break

      if len(operation[0]) > 4 or len(operation[2]) > 4 :
        arranged_problems ="Error: Numbers cannot be more than four digits."
        break

      if operation[1] == "+" : operation.append(operation[0] + operation[2])
      elif operation[1] == "-" : operation.append(operation[0] - operation[2])
      else: 
        arranged_problems = "Error: Operator must be '+' or '-'."
        break

      if len(str(operation[0])) > len(str(operation[2])):
        line1 = line1 + operation[0].rjust(2+len(operation[0])) + "    "
        line2 = line2 + operation[1] + " " + operation[2].right(len(operation[0])) + "    "
        line3 = line3 + (2 + len(operation[0]))*"-" + "    "
        line4 = line4 + operation[3].right(2+len(operation[0]) + "    "
      else : # <<<<< line 33 ERROR >>>#
        line1 = line1 + operation[0].rjust(2+len(operationo[2])) + "    "
        line2 = line2 + operation[1] + " " + operation[2] + "    "
        line3 = line3 + (2 + len(operation[2]))*"-" + "    "
        line4 = line4 + operation[3].right(2+len(operation[2])) + "    "   

  if arranged_problems == "":
    if k == False :
      arranged_problems = line1 +"\n"+ line2 +"\n"+line3
    elif k == True :
      arranged_problems = line1 +"\n"+ line2 +"\n"+line3+"\n"+line4
    else:
      k = False
      arranged_problems = line1 +"\n"+ line2 +"\n"+line3

return arranged_problems        

Thanks in advance :wink:

You haven’t closed the bracket…

1 Like

Wow, cant believe I missed it
Thanks