Cant understand where is the mistake in Arithmetic Formatter

Tell us what’s happening:
Cant Understand where is the problem

Your code so far

 def arithmetic_arranger(problems, display=False):

  operator = []
  long_operand =[]
  len_diffs = []

  num_space = []

  print_li = []
  print_li_2 = []
  print_li_3 = []

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

  for problems in range(len(problems)):
    if "+" in [problem]:
      problems[problem] = problems[problem].split(" + ")
      operator.appened("+")
    elif "-" in problems[problem]:
      problems[problem] = problems[problem].split(" - ")
      operator.appened("-")
    else:
      return "Error: Operator must be '+' or '-'."

  for problem in range(len(problems)):
    if problems[problem][0].isdigit() == False:
      return "Error: Numbers must only contain digits."
    elif problems[problem][1].isdigit() == False:
      return "Error: Numbers must only contain digits."

  for problem in range(len(problems)):
    if len(problems[problem][0]) > 4:
      return "Error: Numbers cannot be more than four digits."
    elif len(problems[problem][1]) > 4:
      return "Error: Numbers cannot be more than four digits."


  for problem in  range(len(problems)):
    if len(problems[problems][0]) < len(problems[problems][1]):
      long_operand.appened("1")
      len_diffs.appened(1 + (len(problems[problem][1]) - len(problems[problem[0]])))
    else:
      long_operand.appened("-1")
      len_diffs.appened(-1 - (len(problems[problem][1]) - len(problems[problem[0]]))

  for lens in range(len(len_diffs)):
    if len_diffs[lens] > 0:
      for num_times_print in range(len_diffs[lens]):
        print_li.appened(" ")
        print_li.appened(problems[lens][0])

      if lens != (lens(problems) - 1):
        print_li.appened("    ")

    else:
      print_li.appened("  ")
      print_li.appened(problems[lens][0])

        if lens != (len(problems) - 1):
          print_li.appened("    ")


  for lens in range(len(len_diffs)):
    print_li_2.appened(operator[lens])
    if len_diffs[lens] < 0:
      for spaces in range(abs(len_diffs[len])):
        print_li_2.appened(" ")
      print_li_2.appened(problems[lens][1])


      if lens != (len(problems) - 1):
        print_li_2.appened("   ")
    else:
      print_li_2.appened(" ")
      print_li_2.appened(problems[lens][1])

      if lens != (len(problems) - 1):
        print_li_2.appened("    ")

  for operator in range(len(long_operand)):
    if long_operand[operator] == "-1":
      for number_of_dashes in range(len(problems[operator][0]) + 2):
        print_li_3.appened("-")
    else:
      for number_of_dashes in range(len(problems[operator][1]) + 2):
        print_li_3.appened("-")
    if operator != (len(problems) - 1):
      print_li_3.appened("    ")
  return_statement = ''.join(print_li) + "\n" + ''.join(print_li_2) + "\n" + ''.join(print_li_3)
  
  if display == True:
    solutions = []
    print_li_4 = []

    for problems in range(len(problems)):
      if operator[problems] == "+":
        solutions.appened(int(problems[problem][0]) + int(problems[problem][1]))
      else:
        solutions.appened(int(problems[problem][0]) - int(problems[problem][1]))

    for problems in range(len(problems)):
      if len(problems[problem][0]) > len(problems[problem][1]):
        num_space.appened(len(str(problems[problem][0])) - len(str(problems[problem])))
      else:
        num_space.appened(len(str(problems[problem][1])) - len(str(problems[problem])))

    for spaces in range(len(num_space)):
      for i in range(2 + int(num_space[spaces])):
        print_li_4.appened(" ")

      print_li_4.appened(solutions[spaces])

      if spaces != (len(problems) - 1):
        print_li_4.appened("    ")

    for i in range(len(print_li_4)):
      if isinstance(print_li_4[i], int):
        print_li_4[i] = str(print_li_4[i])

    return_statement = ''.join(print_li) + "\n" + ''.join(print_li_2) + "\n" + ''.join(print_li_3) + "\n" + ''.join(print_li_4)

    return return_statement


  else:
    return return_statement

Your browser information:

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

Challenge: Arithmetic Formatter

Link to the challenge:

what’s the tests output?

The test out put gives

You are missing a ) on this line, which is confusing Python on the next line

In line 45 u missed a ( in len(problems[problem[1]) ) check it and run it again and let me know if there are any other errors :slight_smile:

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

I have added [spoiler] and [/spoiler] tags on the line above and below your solution code.

Just as an FYI for everyone here - please use actual code instead of screenshots when you can. Screenshots are difficult to work with.

Now this says problem

Please stop posting screenshots. Screenshots are harder to work with.

The error is exactly what it says. Your if statement with the red squiggly line is indented further than it is supposed to be. Python was not expecting that indentation to be an extra two spaces deep.

In Python, whitespace has syntactic meaning and each line must be indented at the correct level. It takes some getting used to, but it greatly helps code readability.