# Arithmetic arranger help

Hey everyone. Can someone help me figure out why my arithmetic arranger is failing? I’ve tested it with multiple variations myself and it seems to work fine, but when I run it in main, it fails a bunch of tests. I’m primarily having a hard time decoding the error messages to know what to fix. Any help would be greatly appreciated.

Here is the code:

``````import re

def right_justified(numbers):
'''Function that takes a string representation of a math problem and returns
it as a string for long-form arithmetic.

numbers: str
return: tuple
'''
parts = numbers.split()
length = ''
for part in parts:
if len(part) > len(length):
length = part

top = parts.rjust(len(length) + 2)
bottom = parts + ' ' + parts.rjust(len(length))
dashes = '-' * (len(length) + 2)
answer = str(int(parts) + int(parts)).rjust(len(length) + 2)

def checks(numbers):
'''Checks if list of string represented math problems pass specified parameters

numbers: list
return: bool or str
'''
check_digits = []
correct_format = []

num_problems = len(numbers) <= 5
if not num_problems:
return 'Error: Too many problems.'

for n in numbers:
check_digits = n.split()
correct_format.extend(re.findall(r'[\d]+ [+-] [\d]+', n))

if not check_digits.isdigit() or not check_digits[-1].isdigit():
return 'Error: Numbers must only contain digits'

elif len(check_digits) > 4 or len(check_digits[-1]) > 4:
return 'Error: Numbers cannot be more than four digits.'

if len(correct_format) < (len(numbers)):
return 'Error: Operator must be "+" or "-".'

return True

'''Take a list of string represented math problems and returns them for long-form math

numbers: list
return: str
'''
tops = ''
bottoms = ''
dashes = ''
new_line = '\n'

res_checks = checks(numbers)

if res_checks != True:
print(res_checks)
return checks(numbers)

else:
for i in numbers:
tops += right_justified(i) + '    '
bottoms += right_justified(i) + '    '
dashes += right_justified(i) + '    '
answers += right_justified(i) + '    '

tops = tops.rstrip()
bottoms = bottoms.rstrip()
dashes = dashes.rstrip()

show = (
f'{tops}{new_line}{bottoms}{new_line}'
)

hide = (
f'{tops}{new_line}{bottoms}{new_line}'
f'{dashes}{new_line}'
)

print(show)
print(hide)

return (
f'{tops}{new_line}{bottoms}{new_line}'