# Can some please tell me what's wrong with my code

Hi I wrote the code arithmetic arranger in Pycharm and then used it in replit
but it is failing 7 tests out of the ten can you please tell me what I am doing wrong

``````def arithmetic_arranger(problem, answer=False):
op = []
num = []
var1 = []
for i in problem:
x = i.split()
var1.append(x)

for i in range(len(var1)):
op.append(var1[i][1])
num.append(var1[i][0])
num.append(var1[i][2])

# print(var1)
# print(op)
# print(num)

def max_of_digits(m):
return max(len(var1[m][0]), len(var1[m][2]))

ans = ''
an = ''
s = ''
k = ''
h = '-'.rjust((5 + max_of_digits(0)) - (max_of_digits(0)))
x = h + '-' * (max_of_digits(0) + 1)

if len(var1) < 6:
if '/' not in op and '*' not in op:
pass
else:
return "Error: Operator must be '+' or '-'."
else:
return 'Error: Too many problems.'

for i in range(len(num)):
if num[i].isdigit() and len(num[i]) < 5:
continue

elif len(num[i]) >= 5:
return "Error: Numbers cannot be more than 4 digits."

elif not num[i].isdigit():
return "Error: Numbers must only contain digits."

for i in range(len(var1)):
if '+' in var1[i]:
y = int(var1[i][0]) + int(var1[i][2])
ans += str(y).rjust(6 + max_of_digits(i))
elif '-' in var1[i]:
y = int(var1[i][0]) - int(var1[i][2])
ans += str(y).rjust(6 + max_of_digits(i))

for i in range(len(var1)):
s += var1[i][0].rjust(6 + max_of_digits(i))
r = var1[i][1].rjust(6 + max_of_digits(i) - (max_of_digits(i) + 1))
k += r + var1[i][2].rjust(max_of_digits(i) + 1)

for i in range(1, len(var1)):
x += ' ' * 4 + '-' * (max_of_digits(i) + 2)
# print(s)
# print(k)
# print(x)
an = ans
else:
an = an
u = s + '\n' + k + '\n' + x + '\n' + an
return u
``````

What error are you getting exactly?

I donâ€™t know how to show it here so I am pasting the link

https://replit.com/@HarishKukka/boilerplate-arithmetic-formatter-10#main.py

Can you please share the challenge link?

is the challenge link https://replit.com/github/freeCodeCamp/boilerplate-arithmetic-formatter

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