# Python Arithmetic Arranger confusion

Hi guys, so first off, I made the entire code in an IDE (because debugging is a lot easier) now when I paste the code on replit and try to run it, it throws up errors.

I understand all the conditions on which errors must be given by the program for example if the program is called with more than 5 problems it must give an error. My program displays the error message in this condition and then ends the program. But replit counts it as a failure (and I have no idea why). So, I’m not sure what kind of error I’m being expected to show.

before I show you the code, let me just say that I do know that the way I have declared lists is completely atrocious and I’ve also used a lot more variables than I needed to. I’m aware of the deficiencies, this is my first Python project so right now I’m just trying to complete it ASAP. Do give your critiques and tips but MOST IMPORTANTLY, plz tell me what replit is expecting from the program

code:

``````def arithmetic_arranger(problems, ans = False):

error = 0

#too many problems check
error = tooManyProbs(problems, error)

if error == 1: return "Error: Too many problems."

prob = [["0" , "+" , "0"],["0" , "+" , "0"],["0" , "+" , "0"],["0" , "+" , "0"],["0" , "+" , "0"]]
dashes = [0,0,0,0,0]

for i in range(len(problems)):

#checking problem not empty and splitting it
if problems[i] != "":
prob[i] = problems[i].split()
error = operatorDigitLenCheck(prob[i], error)

if error == 1: return

for i in range(len(problems)):
dashes[i] = calculateDashes(prob[i],dashes[i])

if ans == True:
if prob[i] == "+":
else:

#printing numbers (and answers, if applicable)

return

def tooManyProbs(problems, error):

if len(problems) > 5:
error = 1

return error

def operatorDigitLenCheck(problem, error):
#checking operator is either + or -
if problem != '+' and problem != '-':
print("Error: Operator must be '+' or '-'.")
error = 1
return error

#checking numbers contain only digits
if problem.isdigit() == False or problem.isdigit() == False:
print("Error: Numbers must only contain digits.")
error = 1
return error

#checking numbers don't exceed length of 4
if len(problem) > 4 or len(problem) > 4:
print("Error: Numbers cannot be more than four digits.")
error = 1
return error

return error

def calculateDashes(problem, dashes):
#finding out how many dashes to add

if len(problem) >=  len(problem):
dashes = 2 + len(problem)
else:
dashes = 2 + len(problem)

return dashes

emptySpaces = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]]

for i in range(len(prob)):
emptySpaces[i] = dashes[i] - len(prob[i])
emptySpaces[i] = dashes[i] - len(prob[i]) - 1

#print first line
for i in range(len(prob)):
if prob[i] != "0" and prob[i] != "0":
for j in range(emptySpaces[i]):
print(" ", end = "")
print(prob[i], "    ", end = "")

print("\n")
#print second line
for i in range(len(prob)):
if prob[i] != "0" and prob[i] != "0":
print(prob[i], end = "")
for j in range(emptySpaces[i]):
print(" ", end = "")
print(prob[i], "    ", end = "")

print("\n")
#print dashes
for i in range(len(dashes)):
if dashes[i] != 0:
for j in range(dashes[i]):
print("-", end = "")
print("    ", end = "")

print("\n")
if ans == True:
if prob[i] != "0" and prob[i] != "0":
for j in range(emptySpaces[i]):
print(" ", end = "")
print(answers[i], "    ", end = "")

return
``````

Challenge: Arithmetic Formatter

First thing that jumps out is that the instructions are to return strings. You should never call print in your code.

It would help if you provide the output from the test suite.

1 Like

There should be an actual error message returned here.

You should not print anything. You must return a string.

You must return the error message as a string.

You must return the error message as a string.

You must return the error message as a string.

Return a string instead of printing.

1 Like

Thank you so much, Jeremy. Really appreciate the help!

1 Like

Sure thing. Feel free to ask more questions as they come up!

1 Like

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