Formatting Errors on Replit but the code works on my IDE.
I was wondering if anyone had any advice on where to go with my code for this problem? The code works when it is run through my IDE but I am having issues getting it to print properly in replit. If anyone has any tips on how to correct this error it is greatly appreciated. I am not lookin for the exact answer necessarily, but just some general idea of what is wrong with the code.
Edit I also am noticing an issue when when the input contains “True” I am getting a rejection. I believe I know how to correct this issue. My one question would be that on the challenge page the Inputs are located within a ( ) but the test cases are in . I imagine the cost differs based on or ().
Thank you!
‘’’
def arithmetic_arranger(problems, bvalue = False):
first_num =
second_num =
dashes =
ans =
for x in problems:
x = x.split()
y = ’ '.join(problems)
y = y.split()
y = sorted(y, key=len, reverse=True)
if len(problems) > 5:
return 'Error: Too many problems.'
break
if x[1] != '+' and x[1] != '-':
return('Error: Operator must be "+" or "-".')
break
if len(y[0]) > 4:
return('Error: Numbers cannot be more than four digits.')
break
if not x[0].isdigit() or not x[2].isdigit():
return('Error: Numbers must only contain digits.')
break
if len(x[0]) > len(x[2]):
largest = len(x[0])
if len(x[0]) < len(x[2]):
largest = len(x[2])
if len(x[0]) == len(x[2]):
largest = len(x[0])
dashes_len = (largest + 2)*'-'
if x[1] == '+': sums = str(int(x[0]) + int(x[2]))
if x[1] == '-': sums = str(int(x[0]) - int(x[2]))
first_num.append(str((6-int(len(x[0])))*' ')+ x[0])
second_num.append((6-len(dashes_len))*' ' + x[1] + (len(dashes_len) - (len(x[2])+1))*' ' + x[2])
dashes.append((6 - len(dashes_len))*' ' + dashes_len)
ans.append((6 - len(sums))*' ' + str(sums))
first_num = (' '.join(first_num))
second_num = (' '.join(second_num))
dashes = (' '.join(dashes))
ans = (' '.join(ans))
arranged_list = [first_num + '\n', second_num + '\n', dashes + '\n']
arranged_problems = ''.join(arranged_list)
if bvalue == True:
arranged_problems += ans
return arranged_problems
‘’’
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36
Challenge: Arithmetic Formatter
Link to the challenge: