Arithmetic_formatter challenge I need help

Hello there,
Every time I run my Code in the terminal it works perfectly fine and I get the right solutions.
However, when I run it in replete.com, it just shows “Error: Too many problems”.
I’m kind of stuck here because I don’t know where the problem is.

**import re
def arithmetic_arranger(problems, solve=False):

if len(problems)>5:
  return "Error: Too many problems."
firstl= ""
secondl=""
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: Numbers must only contain digits."


  num1=problem.split()[0]
  operator=problem.split()[1]
  num2=problem.split()[2]

  if len(num1)>=5 or len(num2)>=5:
      return "Error: Numbers cannot be more than four digits."

  sum = ""

  if(operator == '+'):
    sum=str(int(num1)+int(num2))
  elif (operator =='-'):
    sum=str(int(num1)-int(num2))

  length= 2 + max(len(num1), len(num2))
  top=str(num1).rjust(length)
  bottom=operator+str(num2).rjust(length - 1)
  line=""
  res=str(sum).rjust(length)
  for s in range(length):
      line+= '-'


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

if solve:
    string= firstl+ "\n"+ secondl +"\n"+ lines + "\n"+ sumx
else:
    string= firstl+ "\n"+ secondl +"\n"+ lines
return string

**

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.3 Safari/605.1.15

Challenge: Arithmetic Formatter

Link to the challenge:

Replace replete.com with replit.com; Sorry for that

Replit is just the host-platform, we’d need a link to your actual project so we can look at the error messages.

Hello Jagaya,
thanks for your answer. Is this the link you mean?

“”“boilerplate-arithmetic-formatter-1 - Replit”""

If this is your project then you need a fresh start.
Your code doesn’t look bad, but it seems like you messed with both the main.py and the test_module.py. They all contain an arithmetic-arranger function on top of seemingly missing vital code to properly function.

You are only supposed to work with the arithmetic_arranger.py and touch nothing else. So start a new project and copy that code into the correct file. Then we can see how much works.

1 Like

I just did what you said and something has indeed changed. However there still seems to be something wrong.

boilerplate-arithmetic-formatter-2 - Replit

Hello Jagaya,
I’ve figured out what the latest mistake was. However, thank you very much for your help, this was my first assignment in freeCodeCamp so your help was quite valuable.

1 Like

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