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: