Tell us what’s happening:
Describe your issue in detail here.
my code runs and prints the code properly formatted in VSCode but when I copy and paste it into replit it fails every test. I created a main.py that imports and calls the function with similar parameters as what is on replit. I am coding in VSCode so I can work offline and save my work.
Your code so far
def arithmetic_arranger(*args):
for problems in args:
print(problems[0])
if error_checking(problems[0]) == True:
arranged_problems = format_problems(*args)
return arranged_problems
#check for errors
def error_checking(problems):
#check for 5 or less problems
print(problems)
if len(problems) > 5:
return "Error: Too many problems."
#loop through problems
for problem in problems:
problem = problem.split()
#print(problem)
for x in problem:
#check for operands containing more than 4 digits
if len(x) > 4:
return "Error: Too many digits"
#is digit test
isdigit = "0123456789"
for digit in problem[0]:
if digit not in isdigit:
return "Error: Operand must only contain digits."
for digit in problem[2]:
if digit not in isdigit:
return "Error: Operand must only contain digits."
#operator test
operator = "+-"
for digit in problem[1]:
if digit not in operator:
return "Error: Only additiion and subtrtaction allowed."
return True
def format_problems(*args):
problems = args[0]
line_one =
line_two =
line_three =
line_four =
padding = " "
for problem in problems[0]:
problem = problem.split()
if len(problem[0]) > len(problem[2]):
width = len(problem[0]) + 2
else:
width = len(problem[2]) + 2
w_one = width - len(problem[0])
w_two = width - len(problem[2]) -1
line_one.append((w_one * " ") + problem[0])
line_one.append(" ")
line_two.append(problem[1])
line_two.append((w_two * " ") + problem[2])
line_two.append(" ")
line_three.append(width * "-")
line_three.append(" ")
#solve the problems
if problem[1] == "+":
result = str(int(problem[0]) + int(problem[2]))
else:
result = str(int(problem[0]) - int(problem[2]))
line_four.append((width - len(result)) * " ")
line_four.append(result)
line_four.append(" ")
#concatenate the final string to return
line_one[-1] = "\n"
line_two[-1] = "\n"
line_three[-1] = "\n"
line_four[-1] = "\n"
answered = ''.join(line_one + line_two + line_three + line_four)
no_answer = ''.join(line_one + line_two + line_three)
if len(*args) > 1:
return answered
else:
return no_answer
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0
Challenge: Scientific Computing with Python Projects - Arithmetic Formatter
Link to the challenge: