Arithmetic Arranger syntax errors

Hey everyone. I looked at multiple solutions for this problem and had the bright idea to combine what I’ve learned but how I now i have some errors. I’d like to know what they are and how I can fix them. Thank you

Your code so far

def arithmetic_arranger(problems, solve = True):

  first = ""
  second = ""
  lines = ""
  sumx = ""
  string = ""

  if len(problems) > 5:
    return "Error: Too many problems."
#split up the equation then iterate through problems
  for problem in range (len(problems)):
    if "+" in problems(problem):
      problems[problem] = problems[problem].split("+")
      operators.append("+")
    elif "-" in problems(problem):
      problems[problem] = problems[problem].split("-")
      operators.append("-")
    else:
      return "Error: Operator must be '+' or '-'."
  #iterate the list within the list
  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."
#check if each number is more than four digits
  for problem in range (len(problems)):
    if len(problems[problems][0]) > 4:
      return "Error: Numbers cannot be more than four digits."
    elif len(problems[problems][1]) > 4:
      return "Error: Numbers cannot be more than four digits."

  sum = ""
  if (operator == "+"):
      sum = str(int(firstNumber) + int(secondNumber))
  elif(operator == "-"):
      sum = str(int(firstNumber) - int(secondNumber))
  length = max(len(firstNumber), len(secondNumber))
  top = str(firstNumber.rjust(length)
  bottom = operator + str(secondNumber).rjust(length - 1)
  line = ""
  res = str(sumfirst s in range(length)
    for s in range(length):
      line += "-"

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


    return arranged_problems

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36.

Challenge: Arithmetic Formatter

Link to the challenge:

What errors exactly are you getting?

Hey, thanks for reaching back!

i keep getting this error

 python main.py
Traceback (most recent call last):
File “main.py”, line 2, in
from arithmetic_arranger import arithmetic_arranger
File “/home/runner/boilerplate-arithmetic-formatter-1/arithmetic_arranger.py”, line 42
bottom = operator + str(secondNumber).rjust(length - 1)
^
SyntaxError: invalid syntax
exit status 1

I think this should be problems[problem]

I think there’s a missing end-bracket here -

top = str(firstNumber.rjust(length))

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

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.