Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project

Tell us what’s happening:

The entire project tells me that it is fine, however the last two points he does not want to accept. I do not know what I’m doing wrong

Your code so far

def arithmetic_arranger(problems, show_answers=False):
    if len(problems) > 5:
        return "Error: Too many problems."
    
    char_top = []
    char_bottom = []
    char_line = []
    char_answers = []
    for problem in problems:
        parts = problem.split()
        arg1 = parts[0]
        operator = parts[1]
        arg2 = parts[2]
        if operator not in ["+","-"]:
            return "Error: Operator must be '+' or '-'."
        if len(arg1) > 4 or len(arg2) > 4:
            return 'Error: Numbers cannot be more than four digits.'
        try:
            result = str(eval(problem))
        except:
            return "Error: Numbers must only contain digits."
        max_length = max(len(arg1), len(arg2)) + 2
        char_top.append(arg1.rjust(max_length))
        char_bottom.append(operator + " " + arg2.rjust(max_length - 2))
        char_answers.append(result.rjust(max_length))
        char_line.append('-' * max_length)
    arranged_problems = ""
    if char_top:
        arranged_problems += "    ".join(char_top) + "\n"
    if char_bottom:
        arranged_problems += "    ".join(char_bottom) + "\n"
    if char_line:
        arranged_problems += "    ".join(char_line) 
    if show_answers:
        if char_answers:
            arranged_problems += "    ".join(char_answers)
    return arranged_problems
print(f'\n{arithmetic_arranger(["3801 - 2", "123 + 49"])}')

print(f'\n{arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"],True)}')
print(f'\n{arithmetic_arranger(["24 + 85215", "3801 - 2", "45 + 43", "123 + 49"])}')

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project

This doesn’t output correctly. The answers should be on a new line