Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project

Tell us what’s happening:

how to input some values into my code so that I can monitor my progress

Your code so far

def arithmetic_arranger(problems, show_answers=False):

    if len(problems) > 5:
        return 'Error: Too many problems.'

    for problem in problems:
        prob = problems.split()

        if prob[1] == '*' or prob[1] == '/':
            return "Error: Operator must be '+' or '-'."

        if prob[0].isdigit() or prob[2].isdigit() == False:
            return"Error: Numbers must only contain digits."

        if (prob[0]) or len(prob[2]) > 4:
            return "Error: Numbers cannot be more than four digits."
    else: 
        if prob[1] == '+':
            answer = prob[0] + prob[2]
        else:
            if len(prob[2]) > len(prob[0]):
                answer = prob[2] - prob[0]
            else:
                answer = prob[0] - prob[2]
    
                  



Your browser information:

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

Challenge Information:

Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project

You can see some example function calls in the tests below the instructions.

Make sure to pass the function call to print() and make sure your function returns something.

print(arithmetic_arranger(["3801 - 2", "123 + 49"]))

You can also use print() within your function to check on any variables or outputs


Am I doing it right? or is there something wrong with my code?

add a function call in your editor, like arithmetic_arranger(["3801 - 2", "123 + 49"]), so you can see the error

1 Like

do I add it out of the function?

when you call a function, you write the function call outside the function, yes

1 Like