Help with Arithmetic Formatter not working when I upload to Replit

I wrote my code in VS Code, and the code returns the expected result. When I upload this to Replit, then I fail 5 test and the output in that console prints broken and I can’t pass it. Can you guys please help?

def arithmetic_arranger(problems, displaySolution=False):

    op = {'+': lambda x, y: x + y, '-': lambda x, y: x - y}

    #arranged_problems = ""

    firstLine = ""
    secondLine = ""
    thirdLine = ""
    resultLine = ""
    lines = "------    "

    if len(problems) > 5 :
        return "Error: Too many problems"
        
    else:

        for problem in problems:

            values = problem.split(" ")

            if values[1] == ("*" or "/"):
                return "Error: Operator must be '+' or '-'"
            
            elif len(values[0] or len(values[2])) > 4 :
                return "'Error: Numbers cannot be more than four digits.'"

            else:    

                if displaySolution == True:
                    solution = (op[values[1]](int(values[0]),int(values[2])))
                    
                    firstLine += f"{values[0]:>6}    "
                    secondLine += f"{values[1]} {values[2]:>4}    "
                    thirdLine +=  f"{lines:>6}"
                    resultLine += f"{solution:>6}    "

                else:
                    firstLine += f"{values[0]:>6}    "
                    secondLine += f"{values[1]} {values[2]:>4}    "
                    thirdLine +=  f"{lines:>6}"

    arranged_problems = f"{firstLine}\n{secondLine}\n{thirdLine}\n{resultLine}\n"
    return arranged_problems

I didn’t run the code, but these lines will add 4 spaces on the end of every problem, including the last. The expected strings do not have the 4 spaces on the end of the line.

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